I really can't find anything solid in the docs. Lets say I'm doing something like this:
from django.db.models.signals import post_save
from django.dispatch import receiver
class Item(models.Model):
total_score = models.IntegerField()
def set_score(self):
...
class Review(models.Model):
item = models.ForeignKey(Item, on_delete=models.CASCADE)
score = models.IntegerField()
@receiver(post_save, sender=Review)
def my_handler(sender, **kwargs):
sender.item.set_score()
What I'm trying to do is call set_score()
for the item object, whenever a review object is saved. Is this atomic? I definitely want the whole thing to be atomic, as a situation where a review is saved, but the item's total score is not updated is a recipe for bugs.
transaction.set_rollback(True)
in my code proved this approach to be wrong. Changes applied in a signal that is triggered by a@transaction.atomic
-decorated function are rolled back. – Definiendum