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.
* 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>
* 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>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27998#comment:3>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27998#comment:4>
* 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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27998#comment:4>
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>
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>
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>
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>