-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Should missing dictionary keys be required when serializing mappings. #2342
Comments
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 |
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. |
Eg see confusion here: http://stackoverflow.com/questions/27603669/django-rest-framework-3-required-field-behaviour
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: