【问题标题】:Is django signals excuted inside transaction of sender modelsdjango 信号是否在发送者模型的事务中执行
【发布时间】:2021-04-22 12:17:00
【问题描述】:

我有一个名为 branch 的模型,在保存我正在使用的分支时:

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

我创建 post_save 信号如下:

@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:

她是否需要交易

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

【问题讨论】:

    标签: transactions django-signals


    【解决方案1】:

    我在执行后发现在任何信号装饰器中都不需要事务,当且仅当在保存或删除时使用事务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 2015-09-06
      • 1970-01-01
      • 2011-01-19
      相关资源
      最近更新 更多