django
django copied to clipboard
Update signals.txt
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.
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 ⛵️!
Is there a problem with this patch?
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 :) )
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?