Skip to content
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

fields.Constant is confusing #291

Closed
fayazkhan opened this issue Oct 6, 2015 · 1 comment
Closed

fields.Constant is confusing #291

fayazkhan opened this issue Oct 6, 2015 · 1 comment
Labels

Comments

@fayazkhan
Copy link

fields.Contsant only works for fields which are already present in the object.

from marshmallow import fields, Schema, pprint

class Test(Schema):
    field = fields.Constant(0)
    field2 = fields.Constant(1)

pprint(Test().load({'field': 1}))

I'd expect this code to give me:

UnmarshalResult(data={'field': 0, 'field2': 1}, errors={})

But this is what I get:

UnmarshalResult(data={'field': 0}, errors={})

If this is the expected behavior, it isn't really clear from the docs.
So either the docs or the behavior ought to be changed.

@sloria sloria added the bug label Oct 7, 2015
@sloria
Copy link
Member

sloria commented Oct 7, 2015

This is indeed a bug. Fixed in a69622c. Thanks @fayazkhan for reporting.

@sloria sloria closed this as completed Oct 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants