-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Fields with 'allow_null=True' should imply a default serialization value #5518
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
Conversation
Aside from discussions about whether flags should imply default values, I'd just would like to point out that if a serializer declares a field then a key for that field should unconditionally exist in the serialized output. The referenced change broke this contract for the first time. Although: I'd agree if this was rejected due to explicit vs implicit. Perhaps requiring a default to be declared in these cases? |
@rpkilby What's the status here? I'm beginning to look at a 3.7.2 (say beginning of next week). Ta! |
@carltongibson Basically, trying to figure out what the correct behavior should be here.
That all said:
Is this contract actually true, or is it an assumption made as a result of the previous behavior? Pinging @tomchristie for input here. |
At this point, I'm kind of leaning towards accepting the PR. It allows correct serialization of fields when no object relation exists. However, when coupled with |
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.
OK. We're going to take this. Ultimately it seems entailed by the decisions we've already made, and we seemed to agree at each step.
The behaviour now seems consistent. There is (already) a slight change from earlier behaviour; adding default=None
is recommended.
Maybe there's some weird combination of flags for which the behaviour is unexpected, but we need that pinned down in an actual code example if we are to proceed on it.
Even with such an example the answer might be, "use a custom field in that case" — we're not necessarily committed to covering every possible scenario.
For now, at least, we've spent long enough thinking about this one.
Thanks all.
Just as a followup from #5639..
This statement is true, except for non-required fields. Quoting from the
|
The following currently fails as it's missing a
default
value for serialization.The question is whether or not
allow_null=True
should implydefault=None
.Thanks to @eschercode for pointing this out here.
cc @xordoquy