Opened 7 years ago
Last modified 20 months ago
#28283 new Bug
_changeform_view sends wrong object after ModelForm validation
Reported by: | ddein | Owned by: | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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?
Change History (4)
follow-up: 2 comment:1 by , 7 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 7 years ago
Replying to Tim Graham:
I think this is related to this note 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.
comment:3 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 20 months ago
Owner: | removed |
---|---|
Status: | assigned → new |
I think this is related to this note in the documentation: