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

Allow required false and default #4692

Merged
merged 3 commits into from
Mar 7, 2017
Merged

Allow required false and default #4692

merged 3 commits into from
Mar 7, 2017

Conversation

TBeijen
Copy link
Contributor

@TBeijen TBeijen commented Nov 21, 2016

Fix for the issue described in #2785.

When serializing an dict or object, now the default value is used if the key or attribute is missing from the dict or object. Previously a KeyError or AttributeError was raised.

Two tests failed after implementing the change, which was to be expected as they specifically targeted the behaviour of key or attribute being required even if default is set for the field (serializers.py, TestNotRequiredOutput).
They have been replaced by tests targeting the use of defaults when key or attribute is not present in the instance.

Deserialization seems unaffected.

What isn't clear to me is what the rationale was of explicitly requiring the instance key/attribute to be present, even if a default is provided, so I'm wondering if there's a scenario I'm overlooking.

Tibo Beijen added 3 commits November 20, 2016 17:07
Added tests for using default when default is callable.
Fixed field get_attribute(), now uses get_default() instead of default.
@TBeijen
Copy link
Contributor Author

TBeijen commented Nov 21, 2016

On a sidenote: What's the policy on using pytest? I see quite some pytest constructs being used (with pytest.raises) but no pytest.mark.parametrize.

The tests added here can probably benefit from using parameters, so I'd be glad to add that.

@tomchristie
Copy link
Member

Looks good to me, yes! Tho let's hold it to the next major release since it changes the behavior.

@tomchristie
Copy link
Member

What's the policy on using pytest?

Probably just to use py.test's canonical style wherever possible. More than happy to review further changes to bring us more into line there.

@tomchristie tomchristie merged commit cf5d401 into encode:master Mar 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants