I am writing a small audit log app in Django, which hooks into various signals and writes events to the database. Unfortunately, some of those events are fired already before the corresponding table exists, leading to all sorts of trouble.
To avoid this, I tried to add some trigger to temporarily disable logging during a migration
/ syncdb
- something like this:
from django.db.models.signals import pre_save, post_save, pre_delete
from django.db.models.signals import pre_syncdb, post_syncdb
from south.signals import pre_migrate, post_migrate
IS_MIGRATING = False
@receiver(post_save)
def log_model_update(sender, **kwargs):
if IS_MIGRATING:
return
...
@receiver(pre_syncdb)
@receiver(pre_migrate)
def _disable_auditlog(sender, **kwargs):
global IS_MIGRATING
IS_MIGRATING = True
Unfortunately, this does not work as intended. What am I missing? Or is there an "official" way to do this?
In Django it's possible to disconnect signals. So you can try disconnecting the signals somewhere before the migration code that's causing trouble
Must clarify that I haven't tried it so am not entirely sure if it will work but I hope it helps in some way