[Django] #30839: Form Field’s __deepcopy__ does not (deep)copy the error messages dictionary

18 views
Skip to first unread message

Django

unread,
Oct 4, 2019, 12:26:38 PM10/4/19
to django-...@googlegroups.com
#30839: Form Field’s __deepcopy__ does not (deep)copy the error messages dictionary
--------------------------------------+------------------------
Reporter: Meiyer | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.11
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 |
--------------------------------------+------------------------
The `__deepcopy__` method defined for the formfields
(https://github.com/django/django/blob/146086f219d01dbb1cd8c089b5a5667e396e1cc4/django/forms/fields.py#L200)
performs a shallow copy of self and does not include additional treatment
for the `error_messages` dictionary. As a result, all copies of the same
field share the same dictionary and any modification of either the
dictionary or the error message itself for one formfield is immediately
reflected on all other formfiels.

This is relevant for Forms and ModelForms that modify the error messages
of their fields dynamically: while each instance of the specific form
(e.g., `ProfileForm`) is expected to have a set of fields “sealed” away
from other instances of the same `ProfileForm`
(https://github.com/django/django/blob/146086f219d01dbb1cd8c089b5a5667e396e1cc4/django/forms/forms.py#L95),
in fact all these instances share the same error messages, resulting in
incorrectly raised errors.

Confirmed for versions of Django going back to 1.11.

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

Django

unread,
Oct 7, 2019, 3:03:00 AM10/7/19
to django-...@googlegroups.com
#30839: Form Field’s __deepcopy__ does not (deep)copy the error messages.
------------------------+------------------------------------

Reporter: Meiyer | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: master
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 felixxm):

* version: 1.11 => master
* stage: Unreviewed => Accepted


Comment:

Thanks for this report. I attached a simple test.

Reproduced at f52022ad96356d4b1061610f2b74ea4d1956a608.

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

Django

unread,
Oct 7, 2019, 3:03:26 AM10/7/19
to django-...@googlegroups.com
#30839: Form Field’s __deepcopy__ does not (deep)copy the error messages.
------------------------+------------------------------------

Reporter: Meiyer | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: master
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 felixxm):

* Attachment "test-30839.diff" added.

Simple test.

Django

unread,
Oct 7, 2019, 11:45:20 AM10/7/19
to django-...@googlegroups.com
#30839: Form Field’s __deepcopy__ does not (deep)copy the error messages.
------------------------+------------------------------------------
Reporter: Meiyer | Owner: Hasan Ramezani
Type: Bug | Status: assigned

Component: Forms | Version: master
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 Hasan Ramezani):

* owner: nobody => Hasan Ramezani
* status: new => assigned


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

Django

unread,
Oct 7, 2019, 3:37:28 PM10/7/19
to django-...@googlegroups.com
#30839: Form Field’s __deepcopy__ does not (deep)copy the error messages.
------------------------+------------------------------------------
Reporter: Meiyer | Owner: Hasan Ramezani
Type: Bug | Status: assigned
Component: Forms | Version: master
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 Hasan Ramezani):

* has_patch: 0 => 1


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

Django

unread,
Oct 8, 2019, 4:29:32 AM10/8/19
to django-...@googlegroups.com
#30839: Form Field’s __deepcopy__ does not (deep)copy the error messages.
------------------------+------------------------------------------
Reporter: Meiyer | Owner: Hasan Ramezani
Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
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 Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"a28d1b38e55cf588cfaae97de6a575d5c9f90a96" a28d1b3]:
{{{
#!CommitTicketReference repository=""
revision="a28d1b38e55cf588cfaae97de6a575d5c9f90a96"
Fixed #30839 -- Fixed Field.__deepcopy__() so forms don't share error
messages.
}}}

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

Django

unread,
Oct 8, 2019, 4:29:32 AM10/8/19
to django-...@googlegroups.com
#30839: Form Field’s __deepcopy__ does not (deep)copy the error messages.
------------------------+------------------------------------------
Reporter: Meiyer | Owner: Hasan Ramezani
Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"7c70aa8f6376d761bd6d4bc075d232ee6e91f8f2" 7c70aa8f]:
{{{
#!CommitTicketReference repository=""
revision="7c70aa8f6376d761bd6d4bc075d232ee6e91f8f2"
[3.0.x] Fixed #30839 -- Fixed Field.__deepcopy__() so forms don't share
error messages.

Backport of a28d1b38e55cf588cfaae97de6a575d5c9f90a96 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages