Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#30162 closed Bug (duplicate)

Model error_message 'required' gets overridden by default_error_message

Reported by: Oskar Haller Owned by: nobody
Component: Forms Version: 2.1
Severity: Normal Keywords: custom model error_messages overwritten
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Oskar Haller)

When creating a custom user model I tried the following.

error_messages={'required': _('Please enter your last name.')}

However, it get's overridden by the default_error_message "This field is required."

Unless I specify the 'required' error_message in my form.

This is related to this bug-report 5-years ago https://code.djangoproject.com/ticket/22105 . Is the behavior above still considered 'deliberate'. If so could you elaborate on it? I really see no explanation why this could be wanted.

Change History (3)

comment:1 by Oskar Haller, 6 years ago

Description: modified (diff)
Summary: Model error_message 'required' gets overwritten by default_error_messageModel error_message 'required' gets overridden by default_error_message

comment:2 by Tim Graham, 6 years ago

Component: UncategorizedForms
Resolution: duplicate
Status: newclosed

It's documented:

Error messages defined on model fields are only used when the ValidationError is raised during the model validation step and no corresponding error messages are defined at the form level.

Changing the behavior would be backwards incompatible. If you want to propose changing it, try putting together a patch and presenting a proposal on the DevelopersMailingList. That said, the rationale at ticket:22105#comment:1 makes sense to me so I'm not sure that a proposal has much chance of success.

I'd ask that you not create duplicate tickets (of #22105 in this case) and instead use DevelopersMailingList for design decision reconsiderations.

comment:3 by Oskar Haller, 6 years ago

Alright, thanks for the link to the documentation and clarification. I'll post the link under the old ticket as well.

Note: See TracTickets for help on using tickets.
Back to Top