[Django] #27947: error_messages does not work on SlugField in ModelForm

39 views
Skip to first unread message

Django

unread,
Mar 16, 2017, 8:45:50 AM3/16/17
to django-...@googlegroups.com
#27947: error_messages does not work on SlugField in ModelForm
----------------------------------------------+------------------------
Reporter: Jimmy Merrild Krag | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------------+------------------------
I have the following field in a model:


{{{
reference = models.SlugField(
max_length=20,
blank=False, null=False,
error_messages={
'invalid': _('A reference may only contain letters, numbers,
underscores and hyphens.'),
})
}}}


however, when submitting the field in a `ModelForm` with invalid content
(e.g. containing a space character) the error message is the default one
for `SlugField` and not the one I set.

--
Ticket URL: <https://code.djangoproject.com/ticket/27947>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 16, 2017, 9:36:57 AM3/16/17
to django-...@googlegroups.com
#27947: Document that model field error_messages don't carry over to forms
--------------------------------------+------------------------------------

Reporter: Jimmy Merrild Krag | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* component: Uncategorized => Documentation
* stage: Unreviewed => Accepted
* type: Bug => Cleanup/optimization


Comment:

I was surprised about this behavior but according to
ticket:13693#comment:10, it's expected. The documentation should clarify
this.

--
Ticket URL: <https://code.djangoproject.com/ticket/27947#comment:1>

Django

unread,
Mar 16, 2017, 10:07:50 AM3/16/17
to django-...@googlegroups.com
#27947: Document that model field error_messages don't carry over to forms
--------------------------------------+------------------------------------
Reporter: Jimmy Merrild Krag | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Jimmy Merrild Krag):

So how should I override my error messages?
Right now I do
{{{
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)

# Correct error message for reference field
reference_field = Plan._meta.get_field('reference')
self.fields['reference'].error_messages.update(reference_field.error_messages)
}}}
which I think is ugly

--
Ticket URL: <https://code.djangoproject.com/ticket/27947#comment:2>

Django

unread,
Apr 6, 2017, 11:23:11 AM4/6/17
to django-...@googlegroups.com
#27947: Document that model field error_messages don't carry over to forms
-------------------------------------+-------------------------------------
Reporter: Jimmy Merrild Krag | Owner: Taavi
Type: | Teska
Cleanup/optimization | Status: assigned

Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Taavi Teska):

* owner: nobody => Taavi Teska
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/27947#comment:3>

Django

unread,
Apr 6, 2017, 12:18:27 PM4/6/17
to django-...@googlegroups.com
#27947: Document that model field error_messages don't carry over to forms
-------------------------------------+-------------------------------------
Reporter: Jimmy Merrild Krag | Owner: Taavi
Type: | Teska
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Taavi Teska):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/8316 PR 8316]

--
Ticket URL: <https://code.djangoproject.com/ticket/27947#comment:4>

Django

unread,
Apr 7, 2017, 6:06:33 AM4/7/17
to django-...@googlegroups.com
#27947: Document that model field error_messages don't carry over to forms
-------------------------------------+-------------------------------------
Reporter: Jimmy Merrild Krag | Owner: Taavi
Type: | Teska
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Rivo Laks):

* stage: Accepted => Ready for checkin


Comment:

LGTM

--
Ticket URL: <https://code.djangoproject.com/ticket/27947#comment:5>

Django

unread,
Apr 10, 2017, 2:24:54 PM4/10/17
to django-...@googlegroups.com
#27947: Document that model field error_messages don't carry over to forms
-------------------------------------+-------------------------------------
Reporter: Jimmy Merrild Krag | Owner: Taavi
Type: | Teska
Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"5dbf1c4b23cda915369f4895be293369575238d0" 5dbf1c4b]:
{{{
#!CommitTicketReference repository=""
revision="5dbf1c4b23cda915369f4895be293369575238d0"
Fixed #27947 -- Doc'd that model Field.error_messages often don't
propagate to forms.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27947#comment:6>

Django

unread,
Apr 10, 2017, 2:25:09 PM4/10/17
to django-...@googlegroups.com
#27947: Document that model field error_messages don't carry over to forms
-------------------------------------+-------------------------------------
Reporter: Jimmy Merrild Krag | Owner: Taavi
Type: | Teska
Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.8
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"c3d3aeeafad1562ab82b250a55e09c2f513b0105" c3d3aee]:
{{{
#!CommitTicketReference repository=""
revision="c3d3aeeafad1562ab82b250a55e09c2f513b0105"
[1.11.x] Fixed #27947 -- Doc'd that model Field.error_messages often don't
propagate to forms.

Backport of 5dbf1c4b23cda915369f4895be293369575238d0 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27947#comment:7>

Reply all
Reply to author
Forward
0 new messages