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

Correct allow_null behaviour when required=False #5888

Merged
merged 4 commits into from Mar 20, 2018

Conversation

carltongibson
Copy link
Collaborator

@carltongibson carltongibson commented Mar 20, 2018

This PR reverts #5639. There required=False would override the implicit default coming from allow_null, omitting the field from inclusion. This was incorrect, as reported in #5708.

  • Adds a test for #5708. (Thanks @ticosax for the original report and test)
  • Reverts #5639
  • Adjusts Field docs slightly.

Closes #5708.

There's a slight BC issue here — although we're restoring an older behaviour. Overriding data to remove the offending field if None would serve as a fallback.

TODO:

  • Release notes for behaviour change here.

@carltongibson carltongibson added this to the 3.8 Release milestone Mar 20, 2018
@carltongibson carltongibson requested a review from rpkilby Mar 20, 2018
Ref encode#5708: allow_null should imply default=None, even for non-required fields.

flake8
default is prior to allow_null. allow_null implies an outgoing default=None.
carltongibson added a commit that referenced this issue Mar 20, 2018
@carltongibson carltongibson merged commit 6c0c69e into encode:master Mar 20, 2018
1 check passed
@carltongibson carltongibson deleted the 38/allow_null branch Mar 20, 2018
carltongibson added a commit that referenced this issue Mar 26, 2018
carltongibson added a commit that referenced this issue Apr 3, 2018
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this issue Nov 17, 2020
* Revert "Non-required fields with 'allow_null=True' should not imply a default value (encode#5639)"
    This reverts commit 905a557.
    Closes encode#5708

* Add test for allow_null + required=False
    Ref encode#5708: allow_null should imply default=None, even for non-required fields.

* Re-order allow_null and default in field docs
    default is prior to allow_null. allow_null implies an outgoing default=None.

* Adjust allow_null note.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant