[Django] #28283: _changeform_view sends wrong object after ModelForm validation

11 views
Skip to first unread message

Django

unread,
Jun 7, 2017, 6:00:43 PM6/7/17
to django-...@googlegroups.com
#28283: _changeform_view sends wrong object after ModelForm validation
-----------------------------------------+------------------------
Reporter: ddein | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master
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 noticed strange behavior when changing the form of the admin. If I try
to save the form with an error, some functions (`get_fieldsets`,
`get_prepopulated_fields`, `get_readonly_fields`, `get_inline_formsets`,
something else) get the wrong object after validation. See here:
https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1436-L1437
It seems to me not obvious, that after call `is_valid`, object `obj` will
be changed. The quick solution for me was the following:
{{{
form = ModelForm(request.POST, request.FILES, instance=copy.copy(obj))
}}}
But maybe the problem elsewhere. Has anyone encountered a similar one, is
this a mistake or normal behavior?

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

Django

unread,
Jun 8, 2017, 9:43:06 AM6/8/17
to django-...@googlegroups.com
#28283: _changeform_view sends wrong object after ModelForm validation
-------------------------------+------------------------------------

Reporter: ddein | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | 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 Tim Graham):

* stage: Unreviewed => Accepted


Comment:

I think this is related to this note
[https://docs.djangoproject.com/en/dev/topics/forms/modelforms
/#validation-on-a-modelform in the documentation]:
The cleaning process modifies the model instance passed to the
`ModelForm` constructor in various ways. For instance, any date fields on
the model are converted into actual date objects. Failed validation may
leave the underlying model instance in an inconsistent state and therefore
it’s not recommended to reuse it.

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

Django

unread,
Jun 8, 2017, 10:34:21 AM6/8/17
to django-...@googlegroups.com
#28283: _changeform_view sends wrong object after ModelForm validation
-------------------------------+------------------------------------

Reporter: ddein | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | 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
-------------------------------+------------------------------------

Comment (by ddein):

Replying to [comment:1 Tim Graham]:


> I think this is related to this note
[https://docs.djangoproject.com/en/dev/topics/forms/modelforms
/#validation-on-a-modelform in the documentation]:

Alright, I can check my code and not allow this error. But we are talking
about the code that is used in administration and obviously a correction
is needed here.

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

Django

unread,
Jun 8, 2017, 10:45:45 AM6/8/17
to django-...@googlegroups.com
#28283: _changeform_view sends wrong object after ModelForm validation
-------------------------------+------------------------------------
Reporter: ddein | Owner: ddein
Type: Bug | Status: assigned
Component: contrib.admin | 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 ddein):

* owner: nobody => ddein
* status: new => assigned


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

Django

unread,
Mar 21, 2023, 6:10:31 AM3/21/23
to django-...@googlegroups.com
#28283: _changeform_view sends wrong object after ModelForm validation
-------------------------------+------------------------------------
Reporter: ddein | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: dev

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 Mariusz Felisiak):

* owner: ddein => (none)
* status: assigned => new


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

Reply all
Reply to author
Forward
0 new messages