You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When validating a field, all of its error messages are saved and appended to the list of messages for that field name in call_and_store, but for fields.Nested with many=True the error messages for child elements of the collection are saved and stored in a dictionary keyed by the element index. This causes the following exception on this minimal test case:
Traceback (most recent call last):
File "/home/andrew/misc/marshmallow/tests/test_schema.py", line 1238, in test_all_errors_on_many_nested_field_with_validates_decorator
_, errors = outer.load({'inner': [{}]})
File "/home/andrew/misc/marshmallow/marshmallow/schema.py", line 539, in load
result, errors =self._do_load(data, many, partial=partial, postprocess=True)
File "/home/andrew/misc/marshmallow/marshmallow/schema.py", line 610, in _do_loadself._invoke_field_validators(data=result, many=many)
File "/home/andrew/misc/marshmallow/marshmallow/schema.py", line 789, in _invoke_field_validators
field_obj=field_obj
File "/home/andrew/misc/marshmallow/marshmallow/marshalling.py", line 74, in call_and_store
errors.setdefault(field_name, []).extend(err.messages)
AttributeError: 'dict' object has no attribute 'extend'
The text was updated successfully, but these errors were encountered:
Fixesmarshmallow-code#298. When validating a field, all of its error messages are saved
and appended to the list of messages for that field name in
call_and_store, but for fields.Nested with many=True the error messages
for child elements of the collection are saved and stored in a
dictionary keyed by the element index.
This change introduces a _field key to the errors dictionary of a Nested
field for validation errors raised about the field as a whole, rather
than any one element. For example:
>>> from marshmallow import (
... fields, validates, Schema, ValidationError,
... )
>>> class Inner(Schema):
... x = fields.Int()
...
>>> class Outer(Schema):
... inner = fields.Nested(Inner, many=True)
...
... @validates('inner')
... def check_length(self, data):
... if len(data) < 3:
... raise ValidationError('Not enough elements.')
...
>>> o = Outer()
>>> _, errors = o.load({'inner': [{'x': 123}, {'x': 'abc'}]})
>>> errors # doctest: +NORMALIZE_WHITESPACE
{'inner': {1: {'x': ['Not a valid integer.']},
'_field': ['Not enough elements.']}}
When validating a field, all of its error messages are saved and appended to the list of messages for that field name in
call_and_store
, but forfields.Nested
withmany=True
the error messages for child elements of the collection are saved and stored in a dictionary keyed by the element index. This causes the following exception on this minimal test case:The text was updated successfully, but these errors were encountered: