django icon indicating copy to clipboard operation
django copied to clipboard

Update signals.txt

Open lbt opened this issue 3 years ago • 2 comments

As per the additional note: signals running in a post_save() may notify remote systems too soon for them to read data.

This happened when using MQTT to notify a remote 'desktop' django app to reload an object due to db changes.

I solved this issue and then found that others had similar problems: https://ken-dev.info/django-tricks/2019/10/04/django-signals-in-transaction.html

I hope I have the syntax correct as I have not done a local build.

lbt avatar May 14 '21 08:05 lbt

Hello @lbt! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

github-actions[bot] avatar May 14 '21 08:05 github-actions[bot]

Is there a problem with this patch?

lbt avatar Dec 06 '21 17:12 lbt

I am a little confused. This is not "recommending signal use". Someone reading these docs is already using signals :)

It is pointing out that signals may occur during a transaction and may not have been written to the DB yet. The impact of this is illustrated through reasonable real-world examples (I know they're real-world because of the links I provided).

So this documentation addresses known confusion that multiple users have encountered (see my link) and points at another area of the documentation that seems relevant.

I'm keen to adapt it in a way that you feel is suitable. Your concern is that it's "too specific" even though the exampes are actually fairly diverse. Would removing the examples help with your concerns

I suppose it could be trimmed to be a simple statement of fact with no supporting examples

Model signals such as ``post_save`` may be running inside a transaction
and may not have been written to the database.

In such situations consider calling :meth:`~django.db.transaction.on_commit`
from the signal handler.

(I personally feel that the examples help with the comprehension which is why I included them :) )

lbt avatar Sep 13 '22 10:09 lbt

Hi @lbt. Thanks for the follow-up

I asked @felixxm. He pointed out there's an open ticket here: https://code.djangoproject.com/ticket/24228 🎩

So a fresh one Fixed #24228 -- ... with something along the lines of...

The following signals are sent inside db transactions: ...

If you want to ensure running handler when changes are commited use :meth:`~django.db.transaction.on_commit`, as per the ref:`performing-actions-after-commit` docs. 

Would likely be a win. How's that sound to you?

carltongibson avatar Sep 14 '22 08:09 carltongibson