`cattrs.structure` is failing `detailed_validation=True` behavior with validations
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start by running the provided reproduction against cattrs 23.1.2, focusing on cattrs.structure with detailed validation and the resulting cattrs.BaseValidationError. Inspect how validation failures are aggregated and rendered by cattrs.transform_error; done means the reported result includes the validation failures for both test_data_1 and test_data_2 rather than only one error.
Written by the indexing model from the issue text.
Description
- cattrs version: 23.1.2
- Python version: 3.10
- Operating System: windows 10
- IDE: Pycharm 2023.1 Professional Edition
Description
cattrs.structure is seemingly failing to properly aggregate validation failures, even when explicitly setting detailed_validation=True on new converter.
What I Did
This will result in ['invalid value @ $'] which is unexpected.
import cattrs
from attrs import define
from attrs import field, validators
@define
class TestModel:
test_data_1: float = field(validator=[validators.instance_of(float), validators.lt(100)])
test_data_2: str = field(validator=validators.max_len(3))
@test_data_1.validator
def _check_scale(self, attribute, value):
if int(log10(value)) + 1 > 1:
raise ValueError("value significant figures is greater than 1")
data = {"test_data_1": 110, "test_data_2": "abcdefj"}
try:
print(cattrs.structure(data, TestModel))
except cattrs.BaseValidationError as e:
print(cattrs.transform_error(e))
If I print out the exceptions from e: (ValueError("'test_data_1' must be < 100: 110.0"),)
Unless I'm missing something very critical, this seems like a bug.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 159
- Avg merge
- 12h 21m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-attrs/cattrs
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
python-attrs/cattrs#761 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
python-attrs/cattrs#513 · 4 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
python-attrs/cattrs#779 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 85/100
python-attrs/cattrs#774 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
python-attrs/cattrs#746 · 2 comments ·
All issues in python-attrs/cattrs
Similar issues
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100