The 'required=False' flag has always been for if input is required when validating. For output we always require all fields to be present on the object.
For regular object this works fine - even if an attribute is unset, it will at least still exist. With mappings however the key may simply be missing. What's particularly odd here is that input data could successfully validate, but then 'serializer.data' could still raise an error as one of the fields could have been non-required.
Ideally we don't want to silently ignore missing attributes as that's likely to be eg a misnamed field and it shouldn't simply be blank. However for dictionaries, perhaps we should silently skip missing keys on output?
The text was updated successfully, but these errors were encountered:
I would rather not special case dictionaries if we can, as I believe it's a valid issue for objects with missing attributes as well (that aren't pre-filled, like non-model objects).
My main question for this is what should we assume the default value is? I'm inclined to lead towards something with the default argument here, but then I think that ignores the required=False problem.
My main question for this is what should we assume the default value is?
Omitting the field entirely would make sense. I'm still leaning towards allowing omission from dicts but not from objects. Again, missing attributes will indicate user errors, missing dictionary keys can occur in otherwise totally valid REST framework code.