[Django]-Failing fixture load: DoesNotExist: … matching query does not exist

16👍

I had pre_save and post_save signal triggers on my Company model. These were not checking the raw param and were trying to do some smart things on database values which did not exist.

1👍

When fixture files are processed, the data is saved to the database as is. Model defined save() methods are not called, and any pre_save or post_save signals will be called with raw=True since the instance only contains attributes that are local to the model what-s-a-fixture.

from django.db.models.signals import post_save
from .models import MyModel

def my_handler(**kwargs):
    # disable the handler during fixture loading
    if kwargs['raw']:
        return
    ...

post_save.connect(my_handler, sender=MyModel)
👤gtlee

Leave a comment