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

Should missing dictionary keys be required when serializing mappings. #2342

tomchristie opened this issue Dec 22, 2014 · 2 comments


Copy link

tomchristie commented Dec 22, 2014

Eg see confusion here:

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 '' 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?

Copy link

kevin-brown commented Dec 23, 2014

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.

Copy link
Member Author

tomchristie commented Dec 26, 2014

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.

@tomchristie tomchristie modified the milestone: 3.0.3 Release Dec 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants