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
Improve composite field child errors #5655
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rpkilby
force-pushed
the
child-field-errors
branch
from
December 5, 2017 06:42
29b4ab2
to
9fc2a5d
Compare
rpkilby
changed the title
[wip] Improve composite field child errors
Improve composite field child errors
Dec 21, 2017
rpkilby
force-pushed
the
child-field-errors
branch
2 times, most recently
from
December 21, 2017 23:53
9704f0f
to
1bb3669
Compare
I think this is ready for review. One note - the error dict for a ListField is keyed by a value's index, however JSON dictionaries only accept strings as keys. So, while the underlying error detail may look like: {0: ['This field may not be null.']} The rendered JSON will look like {
"0": ["This field may not be null."]
} |
carltongibson
approved these changes
Jan 2, 2018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Great. Thanks @rpkilby!
6 tasks
pchiquet
pushed a commit
to pchiquet/django-rest-framework
that referenced
this pull request
Nov 17, 2020
* Fixup DictField test descriptions * Nest ListField/DictField errors under the idx/key * Add nested ListField/DictField tests
joshuarli
added a commit
to getsentry/sentry
that referenced
this pull request
Mar 23, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3274
This is an extension of the discussion in #5644. Errors raised on composite fields (
DictField
&ListField
) are confusing, since child validation errors don't contain any indication of what index/key failed.As stated by the django docs, the hstore field accepts nulls as values.
With the below input data, we currently exhibit the following error:
The above error is not helpful, since it fails to mention that this applies to the
"second"
key. The proposed solution is to nest the errors by index/key.before:
{'attributes': ['This field may not be null.']}
after:
{'attributes': {'second': ["This field may not be null."]}}
TODO:
Errors should be tested against HTML forms.ListField/DictField inputs are non-functional.