-
-
Notifications
You must be signed in to change notification settings - Fork 120
Open
Labels
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.