-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
When passing many=True to PolyField, errors are not keyed by index like they are with Nested.
Here's an example to reproduce the issue:
from marshmallow import Schema, fields, validate, ValidationError
from marshmallow_polyfield import PolyField
class ChildSchema(Schema):
foo = fields.Str(validate=validate.Length(max=3))
class ParentSchema(Schema):
children = fields.Nested(ChildSchema, many=True)
class ParentPolySchema(Schema):
children = PolyField(deserialization_schema_selector=lambda _, __: ChildSchema, many=True)
try:
ParentSchema().load({"children": [{'foo': 'x'}, {'foo': 'invalid'}, {'foo': 'alsoinvalid'}]})
except ValidationError as error:
print('Nested:', error.messages)
try:
ParentPolySchema().load({"children": [{'foo': 'x'}, {'foo': 'invalid'}, {'foo': 'alsoinvalid'}]})
except ValidationError as error:
print('PolyField:', error.messages)
Output:
Nested: {'children': {1: {'foo': ['Longer than maximum length 3.']}, 2: {'foo': ['Longer than maximum length 3.']}}}
PolyField: {'children': {'foo': ['Longer than maximum length 3.']}}
I would expect both errors dictionaries to be the same.
Metadata
Metadata
Assignees
Labels
No labels