[Django] #30662: Add a signal at the end of Model.refresh_from_db()

13 views
Skip to first unread message

Django

unread,
Jul 27, 2019, 3:56:08 AM7/27/19
to django-...@googlegroups.com
#30662: Add a signal at the end of Model.refresh_from_db()
-------------------------------------+-------------------------------------
Reporter: Craig de | Owner: nobody
Stigter |
Type: New | Status: new
feature |
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I have an app that allows callers to subscribe to a `post_save_changed`
signal on particular fields, when those fields have changed.

It works by recording values in the `post_init` signal, then checking
their values in the `post_save` signal, and then triggering its own
`post_save_changed` signal if the values are different.

The problem is that currently there's no way this can detect someone
calling `Model.refresh_from_db()`. If I could detect that, I would
overwrite the stored values from `post_init` with some new values.
Otherwise my app may detect 'changes' which have actually already been
applied to the database.

A `post_refresh_from_db` signal seems conspicuously absent. Or perhaps
`post_init` should be called again when `refresh_from_db` is called? That
would also solve my problem.

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

Django

unread,
Jul 27, 2019, 3:58:09 AM7/27/19
to django-...@googlegroups.com
#30662: Add a signal at the end of Model.refresh_from_db()
-------------------------------------+-------------------------------------
Reporter: Craig de Stigter | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Craig de Stigter):

Ticket on my app for this: https://github.com/craigds/django-
fieldsignals/issues/17

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

Django

unread,
Jul 29, 2019, 2:06:53 AM7/29/19
to django-...@googlegroups.com
#30662: Add a signal at the end of Model.refresh_from_db().

-------------------------------------+-------------------------------------
Reporter: Craig de Stigter | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* version: 2.2 => master
* resolution: => wontfix


Comment:

Thanks for this ticket, however I think it's quite niche and even with
this signal you will have few missing scenarios e.g. using
`QuerySet.update()` (see #21461).

Needs discussion on the django-developers mailing list in order to be
accepted.

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

Reply all
Reply to author
Forward
0 new messages