-
-
Notifications
You must be signed in to change notification settings - Fork 629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression on list of nullable nested fields #1497
Comments
I was able to track this change down to #1306. This behavior was inherited from Using 2.x you can reproduce this behavior using class S(Schema):
f = fields.Nested(Schema, allow_none=True, many=True)
S().dump(dict(f=[None]))
# MarshalResult(data={u'f': [{}]}, errors={})
When the value of a field is @sloria @lafrech Should |
As far as I can tell there is no documentation that says https://marshmallow.readthedocs.io/en/stable/custom_fields.html#creating-a-field-class |
Hi, from marshmallow import Schema, fields
class S(Schema):
string = fields.String(allow_none=True)
list_of_strings = fields.List(fields.String(allow_none=True))
object = fields.Nested(Schema, allow_none=True)
list_of_objects = fields.List(fields.Nested(Schema, allow_none=True))
print(S().dump(dict(
string=None,
list_of_strings=[None],
object=None,
list_of_objects=[None],
)))
# marshmallow 2
{'string' : None,
'object' : None,
'list_of_objects': [None],
'list_of_strings': [None]}
# marshmallow 3
{'object' : None,
'list_of_objects': [{}],
'list_of_strings': [None],
'string' : None}
print(S().load(dict(
string=None,
list_of_strings=[None],
object=None,
list_of_objects=[None],
)).data)
# marshmallow 2
{'string' : None,
'object' : None,
'list_of_objects': [None],
'list_of_strings': [None]}
# marshmallow 3 -> marshmallow.exceptions.ValidationError: {'list_of_objects': {0: {'_schema': ['Invalid input type.']}}}
# marshmallow 3, if not using the list_of_objects
{'list_of_strings': [None],
'string': None,
'object': None} So, when trying to load a value from a
Whereas, when doing the same thing with a scalar field (
Shouldn't |
in marshmallow 3.0rc9 (the release just before #1306 was merged) class S(Schema):
string = fields.String(allow_none=True)
list_of_strings = fields.List(fields.String(allow_none=True))
object = fields.Nested(Schema, allow_none=True)
list_of_objects = fields.List(fields.Nested(Schema, allow_none=True))
many_nested_objects = fields.Nested(Schema, allow_none=True, many=True)
base_dict = dict(string=None, list_of_strings=[None], object=None, list_of_objects=[None], many_nested_objects=[None])
assert S().dump(base_dict) == base_dict # works in 3.0rc9
assert S().load(base_dict) == base_dict # fails, 'many_nested_objects': [{}] some changes would have to be made on the |
This can be fixed for |
@Meallia pointed out in #1498 that |
Hello,
While porting some code from 2.20 to 3.3, I stumbled upon this change in behavior regarding list of nullable fields.
in 2.20 the following code works:
whereas the same code in 3.3 fails with
AssertionError: assert {'f': [{}]} == {'f': [None]}
I could not find anything related to this in the upgrade instructions or the documentation.
I'm fully aware that this is an edge case and I don't mind looking into it if it's actually considered as a bug.
here are two unit tests that can be used to reproduce this issue:
The text was updated successfully, but these errors were encountered: