Django post save signal getting called twice despite uid

前端 未结 4 1511
[愿得一人]
[愿得一人] 2020-12-16 21:59

I have registered my signal with the callback using the @receiver decorator

@receiver(post_save, sender=User, dispatch_uid=\'ARandomUniqueString         


        
4条回答
  •  无人及你
    2020-12-16 22:46

    I had the same problem with post_save and also post_delete signals. It seems that the session object and LogEntry object were being saved as well creating multiple signals despite setting the dispatch_uid.

    What worked for me was:

    from django.contrib.admin.models import LogEntry
    from django.contrib.sessions.models import Session
    
    ....
    
    if sender in [LogEntry, Session]:
        return 
    else:
        # do your thing here
    

提交回复
热议问题