Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Non-required fields with 'allow_null=True' should not imply a default value#5639
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
rpkilby commentedDec 1, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi@RomuloOliveira, thanks for raising this. The docs do say that
To address a few things...
To clarify, the PR description is not completely correct, and this was not the final behavior.
Yes, this is related to
I don't think it's necessary for this PR. I'll address it separately. |
rpkilby left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
👍
Sinceencode#5639 we are unable to render fields that were rendered previouslywith `allow_null=True`.Backward compatibility is not preserved,because `required=True` and `read_only=True` are conflicting, so in ourcase, some fields just disappeared and it seems there is not way to getthem back.I'm not sure about the fix, but the regression test is probably right.
rpkilby commentedDec 23, 2017
In hindsight, while consistent with the @RomuloOliveira, was there a specific reason why these fields needed to be omitted from the serialized output? It's not clear to me what behavior this is enabling. |
RomuloOliveira commentedDec 26, 2017
@rpkilby I've made this to made In my opinion, it keeps things explicit and do not depend on any other flags combinations to work as expected. In this way, an user do not need to know allcaveats and special behaviour that occurs when flags are combined. I noticed this because after upgrading to 3.7.2 some fields were not consistent with others in an API that I was developing and it took a lot of time to figure out what was causing it. I've thought at first it was a bug before seeing the discussion#5518. I thought it's a bit weird that This discussion was closed and so was#5518, but as an DRF user, I'm asked myself why use implicit values (which can interfere with another flags) and, why use itonly in |
Sinceencode#5639 we are unable to render fields that were rendered previouslywith `allow_null=True`.Backward compatibility is not preserved,because `required=True` and `read_only=True` are conflicting, so in ourcase, some fields just disappeared and it seems there is not way to getthem back.I'm not sure about the fix, but the regression test is probably right.
… default value (encode#5639)"This reverts commit905a557.Closesencode#5708
… default value (encode#5639)"This reverts commit905a557.Closesencode#5708
* Revert "Non-required fields with 'allow_null=True' should not imply a default value (#5639)" This reverts commit905a557.Closes#5708* Add test for allow_null + required=False Ref#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.
* Revert "Non-required fields with 'allow_null=True' should not imply a default value (encode#5639)" This reverts commit905a557.Closesencode#5708* Add test for allow_null + required=False Refencode#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.
Prior to the#5518, all fields with
required=Falseand without a explicit default value were not included in the output.After the patch, even non-required fields now had a default value, which is counter-intuitive if you look at the
requireddocumentation, which saysSet to false if this field is not required to be present during deserialization.This PR restore the original
required=Falsebehaviour. Now, anyrequired=Falsewithout a explicit default value should not be returned in the output.However, it keeps the implicit
default=Nonefor required fields introduced in#5518.Question I: Did I wrote the test in the correct class (
TestNotRequiredOutput) or should it be in theTestDefaultOutputclass?Question II: Is there a reason that the implicit default
Nonevalue forallow_nullis not in theField.get_defaultfunction? Looking at theexcepthandling code, at first it did notsound right.Question III: Should I add to the documentation that
allow_nullimplicitly set adefault=Nonefor required fields?That issue is already closed and it is not my intention to reopen it, but it's a special case that I did not fully understand why not forcing a explicit default value. E.g, what about
allow_blank? Andmany=True? Shouldn't they have a implicit default value too, using the same logic?