I have written some APIs, for which the respective functions executive inside a transaction block. I am calling the save()
method (after some modifications) on instance/s of a/several Model/s, and also consecutively indexing some JSON related information of the instance/s in Elasticsearch. I want the database to rollback even if for some reason the save()
for one of the instances or indexing to the Elasticsearch fails.
Now, the problem is arising that even inside the transaction block, the post_save()
signals gets called, and that is an issue because some notifications are being triggered from those signals.
Is there a way to trigger post_save()
signals only after the transactions have completed successful?
instance.in_transaction = True
, but that did create a lot of the confusion as many of the other developers then missed the handling in their signals. I think, the second approach will be much more easy to handle, and will be with least complications. – Photothermic