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

load_from is overriding field name, instead of acting as an alias #118

Closed
jasonab opened this issue Jul 27, 2016 · 6 comments

Comments

@jasonab
Copy link

commented Jul 27, 2016

In the Marshmallow docs, load_from is specifically named as an alias to the field name:

Additional key to look for when deserializing. Will only be checked if the field’s name is not found on the input dictionary. If checked, it will return this parameter on error.

However, core.py line 276 uses the load_from name to override the arg name, if load_from is specified. This is not in line with marshmallow behavior.

@sloria

This comment has been minimized.

Copy link
Member

commented Nov 6, 2016

@jasonab Just for my understanding: are you expecting that the field name is present in the request, that will be the key used in the errors output?

Example: Given an argdict {'content_type': fields.Str(load_from='Content-Type', required=True)}, webargs will first check if content_type is in the request before checking Content-Type. The errors output will be something like {'content_type': ['Missing data for required field.']}.

@jasonab

This comment has been minimized.

Copy link
Author

commented Nov 6, 2016

Sorry, it's been a few months. :-)

I believe what I was expecting was that webargs would check both names in the request, first the actual key, and then the field name (as you mention in the example). Right now, I believe webargs will only check for the 'Content-Type' key, not 'content_type' in your example.

@sloria

This comment has been minimized.

Copy link
Member

commented Nov 6, 2016

Makes sense. I think the behavior you're describing is the expected behavior, so this can be considered a bug.

PRs welcome =)

sloria added a commit that referenced this issue Nov 20, 2016

@sloria sloria closed this in 13df80e Nov 20, 2016

@jasonab

This comment has been minimized.

Copy link
Author

commented Nov 21, 2016

Thanks for fixing this. Sorry I didn't have a PR, I had some trouble running the tests on my side.

@sloria

This comment has been minimized.

Copy link
Member

commented Nov 21, 2016

No worries!

@lafrech

This comment has been minimized.

Copy link
Member

commented Jan 21, 2018

For the record, this changed in Marshmallow 3 (marshmallow-code/marshmallow#714).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.