-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
error_messages on serializer fields should also be used by validators. #2878
Comments
I see. We automatically add @tomchristie I wonder if we should be forwarding @hobarrera A workaround might be to subclass |
I believe that that makes sense and is what would usually be expected by most developers.
Yes, that's what I did. In case anybody else needs a bit more details on this workaround:
|
Is the proposed enhancement to take the error messages from what's defined on the model level and forward them on? |
Yes, that's what's expected (and it's done for other validators, unless I'm mistaken). |
Seems reasonable to me for us to check the validator codes and apply the field error message if one exists, yup. No objection to this from me. |
+1 any progress on this one? is this saying we can define error message on the Model level as in https://docs.djangoproject.com/en/1.8/ref/models/fields/#error-messages? |
No, if there's progress you'd see it here.
Yup |
cool, if you tell me the general idea for how that should work or where I need to make updates I can take a stab at it... |
You'd need to change something here, at least: That's where a UniqueValidator is automatically added to the serializer for fields with unique constraints. I'm not quite sure how to get the message off of the model field, though. |
Error messages for a specific field are available as |
In the automatically applied UniqueValidator, use the error message from error_messages defined in the model instead of the generic default UniqueValidator message. This fixes encode#2878.
In the automatically applied UniqueValidator, use the error message from error_messages defined in the model instead of the generic default UniqueValidator message. This fixes encode#2878.
you should have indicated what file you added this to. It isn't really helpful just like this |
@iampicca I added this to my serializers, which are in my |
from rest_framework.validators import UniqueValidator email = serializers.EmailField(validators=[ |
This does not show the defined error as expected when the field is not unique. The message is still the default: "This field must be unique.".
The text was updated successfully, but these errors were encountered: