Should missing dictionary keys be required when serializing mappings. · Issue #2342 · encode/django-rest-framework (original) (raw)

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?