[Django] #27998: LogEntry messages do not list m2m fields that were changed when an object is changed via ModelAdmin

10 views
Skip to first unread message

Django

unread,
Mar 30, 2017, 11:31:46 PM3/30/17
to django-...@googlegroups.com
#27998: LogEntry messages do not list m2m fields that were changed when an object
is changed via ModelAdmin
-----------------------------------------+------------------------
Reporter: ljsjl | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
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 |
-----------------------------------------+------------------------
What I expect to happen: m2m fields that are changed via a ModelAdmin in
an update are listed in the appropriate change message in that object's
history.
What happens: m2m fields are not listed in the generated change message

Reproduction: Create a vanilla Django install. Create a group. Assign a
permission to that group. View the group's history, the message will say
"No fields changed."

Cause: It looks like save_related() is called before form.has_changed() or
form.changed_data are evaluated. save_related() calls form.save_m2m()
which updates the relationship table. At this point it looks like
querysets in the ModelForm form.initial have not been evaluated, so when
they are evaluated as part of constructing the change message the database
has already been modified by form.save_m2m(), and so the fields are left
out of form.changed_data.

Fix: Probably call form.has_changed() at some point before save_related().
Happy to put together a patch for changelist_view and changeform_view if
needed and attach to this ticket.

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

Django

unread,
Apr 1, 2017, 9:17:11 PM4/1/17
to django-...@googlegroups.com
#27998: LogEntry messages do not list m2m fields that were changed when an object
is changed via ModelAdmin
-------------------------------+------------------------------------

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

If you're able to, submitting a pull request to GitHub is the best way to
submit a patch.

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

Django

unread,
Apr 5, 2017, 2:39:42 AM4/5/17
to django-...@googlegroups.com
#27998: LogEntry messages do not list m2m fields that were changed when an object
is changed via ModelAdmin
-------------------------------+------------------------------------
Reporter: ljsjl | Owner: ljsjl
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.10

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 ljsjl):

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


Comment:

https://github.com/ljsjl/django/tree/ticket_27998

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

Django

unread,
Apr 25, 2017, 7:53:32 PM4/25/17
to django-...@googlegroups.com
#27998: LogEntry messages do not list m2m fields that were changed when an object
is changed via ModelAdmin
-------------------------------+------------------------------------
Reporter: ljsjl | Owner: ljsjl
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.10

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 ljsjl):

* has_patch: 0 => 1


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

Django

unread,
May 6, 2017, 2:34:51 PM5/6/17
to django-...@googlegroups.com
#27998: LogEntry messages do not list m2m fields that were changed when an object
is changed via ModelAdmin
-------------------------------+------------------------------------
Reporter: ljsjl | Owner: ljsjl
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


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

Django

unread,
Jun 14, 2017, 1:25:57 PM6/14/17
to django-...@googlegroups.com
#27998: LogEntry messages do not list m2m fields that were changed when an object
is changed via ModelAdmin
-------------------------------+------------------------------------
Reporter: ljsjl | Owner: ljsjl
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10
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 Tim Graham <timograham@…>):

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


Comment:

In [changeset:"15b465c584f49a1d43b6c18796f83521ee4ffc22" 15b465c]:
{{{
#!CommitTicketReference repository=""
revision="15b465c584f49a1d43b6c18796f83521ee4ffc22"
Fixed #27998 -- Made ManyToManyField changes logged in admin's object
history.
}}}

Django

unread,
Aug 30, 2017, 2:51:54 PM8/30/17
to django-...@googlegroups.com
#27998: LogEntry messages do not list m2m fields that were changed when an object
is changed via ModelAdmin
-------------------------------+------------------------------------
Reporter: ljsjl | Owner: ljsjl
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10

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 Tim Graham):

I found that this is a regression in Django 1.10 due to
ded502024191053475bac811d365ac29dca1db61 and therefore should be fixed in
the current stable branch, 1.11.x. The fix for #28543 fixes this issue in
a better way (at the form level, rather than only in the admin) but I'm
concerned that the approach I've proposed there, changing the return type
of `ManyToManyField.value_from_object()`, is too risky for a stable
release. I've proposed an [https://github.com/django/django/pull/8993
alternate PR] that modifies `model_to_dict()` instead. It restores the
behavior of `model_to_dict()` returning a list for `ManyToManyField` from
before 67d984413c9540074e4fe6aa033081a35cf192bc.

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

Django

unread,
Aug 31, 2017, 9:35:00 AM8/31/17
to django-...@googlegroups.com
#27998: LogEntry messages do not list m2m fields that were changed when an object
is changed via ModelAdmin
-------------------------------+------------------------------------
Reporter: ljsjl | Owner: ljsjl
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10

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 GitHub <noreply@…>):

In [changeset:"e5bd585c6eb1e13e2f8aac030b33c077b0b70c05" e5bd585]:
{{{
#!CommitTicketReference repository=""
revision="e5bd585c6eb1e13e2f8aac030b33c077b0b70c05"
Fixed #28543 -- Prevented ManyToManyField.value_from_object() from being
lazy.

Previously, it was a QuerySet which could reevaluate to a new value if the
model's data changes. This is inconsistent with other
Field.value_from_object()
methods.

This allows reverting the fix in the admin for refs #27998.
}}}

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

Django

unread,
Aug 31, 2017, 10:13:42 AM8/31/17
to django-...@googlegroups.com
#27998: LogEntry messages do not list m2m fields that were changed when an object
is changed via ModelAdmin
-------------------------------+------------------------------------
Reporter: ljsjl | Owner: ljsjl
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10

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 Tim Graham <timograham@…>):

In [changeset:"20c03399d8fd03484f3ed33d93691c29c2ff5aaf" 20c0339]:
{{{
#!CommitTicketReference repository=""
revision="20c03399d8fd03484f3ed33d93691c29c2ff5aaf"
[1.11.x] Fixed #27998, #28543 -- Restored logging of ManyToManyField
changes in admin's object history.

And prevented ManyToManyField initial data in model forms from being
affected
by subsequent model changes.

Regression in 56a55566a791a11420fe96f745b7489e756fc931.

Partial backport of e5bd585c6eb1e13e2f8aac030b33c077b0b70c05 and
15b465c584f49a1d43b6c18796f83521ee4ffc22 from master
}}}

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

Django

unread,
Aug 31, 2017, 7:49:53 PM8/31/17
to django-...@googlegroups.com
#27998: LogEntry messages do not list m2m fields that were changed when an object
is changed via ModelAdmin
-------------------------------+------------------------------------
Reporter: ljsjl | Owner: ljsjl
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10

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 ljsjl):

Huh, guess I should have followed my initial fix further down the rabbit
hole to Field rather than ModelAdmin behaviour. Thanks to Wonder and Tim
for a better fix.

--
Ticket URL: <https://code.djangoproject.com/ticket/27998#comment:8>

Reply all
Reply to author
Forward
0 new messages