Skip to content

Update fields.md explaining how the source argument affects .validated_data - #10008

Open
Ernest0x wants to merge 1 commit into
encode:mainfrom
Ernest0x:patch-7
Open

Update fields.md explaining how the source argument affects .validated_data#10008
Ernest0x wants to merge 1 commit into
encode:mainfrom
Ernest0x:patch-7

Conversation

@Ernest0x

Copy link
Copy Markdown
Contributor

One may think that, after successful validation, a key in the .validated_data attribute of a serializer always equals the corresponding field name in the serializer. However, that may not be the case if the field has been defined in the serializer with a dotted path value in its source argument. In that case, what is actually included in .validated_data is a nested dictionary that is derived by expanding the dotted path of the source argument. This addition in the documentation clarifies the situation and explains why DRF follows that behavior.

…re of `.validated_data`

One may think that, after successful validation, a key in the `.validated_data` attribute of a serializer always equals the corresponding field name in the serializer. However, that may not be the case if the field has been defined in the serializer with a dotted path value in its `source` argument.  In that case, what is actually included in `.validated_data` is a nested dictionary that is derived by expanding the dotted path of the `source` argument. This addition in the documentation clarifies the situation and explains why DRF follows that behavior.
@AlkiviadisAleiferis

Copy link
Copy Markdown

I had the same misunderstanding and had to turn to the source code to make that functionality clear. That part of the documentation should not be missing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants