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

Nested schemas render None strangely #132

Closed
nickretallack opened this Issue Jan 22, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@nickretallack

nickretallack commented Jan 22, 2015

This is very similar to the other bug I reported. Turns out None renders strangely even when there's no many=True option specified.

from marshmallow import Schema, fields, pprint

class ChildSchema(Schema):
    name = fields.String()

class ParentSchema(Schema):
    child = fields.Nested(ChildSchema)

schema = ParentSchema()
result = schema.dump(object())
pprint(result.data)

Output:

{u'child': {u'name': u''}}

Expected:

{u'child': None}
@sloria

This comment has been minimized.

Member

sloria commented Jan 22, 2015

Pass allow_null=True and you will get the expected result.

class ParentSchema(Schema):
    child = fields.Nested(ChildSchema, allow_null=True)

http://marshmallow.readthedocs.org/en/latest/api_reference.html#marshmallow.fields.Nested

@nickretallack

This comment has been minimized.

nickretallack commented Jan 22, 2015

Ok, that helps, but I still find the default behavior nonsensical. Would anyone want it to do what it is doing? I think allow_null should be the default behavior.

@sloria

This comment has been minimized.

Member

sloria commented Feb 1, 2015

@nickretallack I will consider making allow_null=True the default in 2.0-a. Thanks for the suggestion.

@sloria sloria added this to the 2.0-a milestone Feb 1, 2015

@sloria sloria closed this in db0ffd7 Feb 19, 2015

@sloria

This comment has been minimized.

Member

sloria commented Feb 19, 2015

Decided to change the default to allow_null=True. This will make None serialize to None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment