Search code examples
transactionsdjango-signals

Is django signals excuted inside transaction of sender models


I have a model called branch, at saving branch I am using:

with transaction.atomic():
    #previous processing 
    obj.save()
    #additional codes

I create post_save signal as follow:

@receiver(signals.post_save, sender=Branch)
def update_reporter_header(sender, instance,created, **kwargs):
    """ When Add or Edit a Branch The related data to branch must be change

    Args:
        sender ([Branch]): [the model Who kept under eye when any change]
        instance ([Branch]): [description]
        created ([boolean]): [return true if instance created else False]
    """
    if created:

is the transaction her required or not

        for obj in HeaderFooter.bobjects.all().filter(branch_id=instance.id,customize=False,is_appeare=True):
            obj.data = getattr(instance,obj.name)
            obj.save()
    

Solution

  • I found after execution that no need for transaction inside any signal decorator, if and only if transaction was used at save or delete.