-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Introduce error code for validation errors. #3716
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
Changes from 1 commit
8c29efe
1834760
c7351b3
42f4c55
7971343
24ba3b3
ba21a1e
12e4b8f
2344d22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| from django.utils.translation import ugettext_lazy as _ | ||
|
|
||
| from rest_framework.compat import unicode_to_repr | ||
| from rest_framework.exceptions import ValidationError, ValidationErrorMessage | ||
| from rest_framework.exceptions import ValidationError | ||
| from rest_framework.utils.representation import smart_repr | ||
|
|
||
|
|
||
|
|
@@ -101,10 +101,7 @@ def enforce_required_fields(self, attrs): | |
| return | ||
|
|
||
| missing = { | ||
| field_name: ValidationErrorMessage( | ||
| self.missing_message, | ||
| code='required') | ||
|
|
||
| field_name: self.missing_message | ||
| for field_name in self.fields | ||
| if field_name not in attrs | ||
| } | ||
|
|
@@ -190,9 +187,7 @@ def enforce_required_fields(self, attrs): | |
| 'required' state on the fields they are applied to. | ||
| """ | ||
| missing = { | ||
| field_name: ValidationErrorMessage( | ||
| self.missing_message, | ||
| code='required') | ||
| field_name: self.missing_message | ||
| for field_name in [self.field, self.date_field] | ||
| if field_name not in attrs | ||
| } | ||
|
|
@@ -219,7 +214,7 @@ def __call__(self, attrs): | |
| if queryset.exists(): | ||
| message = self.message.format(date_field=self.date_field) | ||
| raise ValidationError({ | ||
| self.field: ValidationErrorMessage(message, code='unique'), | ||
| self.field: message, | ||
| }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this missing a code or not?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If message is always a single value, then the code is missing yes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So my first thought was wrong, the code is not missing but will have to be exposed in the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is a serializer-level validator, but needs to indicate that the validation error corresponded to a particular field.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To add to my previous comment, this code shows why having the code here is useless:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not really the issue at this point in time. Yes we still need to figure out if and how we'd bridge "these exceptions can have an associated code" with "and here's how we expose that in the serializer API", but the exceptions themselves should include the code.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This the touchy part.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I mean is, whatever we do to construct or expose it later on, this structure looks wrong: while this looks better |
||
|
|
||
| def __repr__(self): | ||
|
|
||
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.
Might as well keep that formatting as-is.
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.
indeed blame my IDE XD