#36108: The `update_field` when using `django.db.models.signals` does not work
with
a custom Model Manager
-------------------------------------+-------------------------------------
Reporter: NicoJJohnson | Owner: (none)
Type: Bug | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
signal,model,manager,filter | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* resolution: => invalid
* status: new => closed
Comment:
[https://forum.djangoproject.com/t/avoiding-duplicate-entries-when-one-or-
more-fields-are-none/37109 This the forum thread referred to in the
report] which I assume could not be included due to spam filter
configuration.
There's something that doesn't add up in this report with regards to
`update_fields` and I believe could be due to
[https://docs.djangoproject.com/en/5.1/ref/signals/#post-save a
misunderstanding of the feature]; the value provided to the save signal
receiver is nothing more than what's passed to `Model.save(update_fields)`
and not the the set of fields that were locally changed from their last
persisted value.
> `update_fields`
>
> The set of fields to update as passed to `Model.save()`, or `None` if
`update_fields` wasn’t passed to `save()`.
In other words Django doesn't keep track of model instance fields that
were assigned a different value since their last retrieval / persistence
to the database and will
[https://docs.djangoproject.com/en/5.1/ref/models/instances/#specifying-
which-fields-to-save default to saving all fields] if `update_fields` is
not specified which is denoted by `update_fields=None` in signal
receivers.
If you want to keep track of which field changed and [https://django-
model-utils.readthedocs.io/en/latest/utilities.html#field-tracker you
should use a third party application for that].
--
Ticket URL: <https://code.djangoproject.com/ticket/36108#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019475adb834-b4049091-db94-45db-8902-546d075d608c-000000%40eu-central-1.amazonses.com.