when restoring data with python manage.py loaddata an error is encountered saying, Change matching query does not exist. The full error is shown at the bottom.
This seems to be related to loaddata not loading models in order and and the post_save failing for Change objects.
This is may be a hacky fix, but to allow loaddata to run, an except has been added to the set_change_updated_at function.
root@5f325946f44e:/home/app/web# python manage.py loaddata stage_2023.04.05.json
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/django/db/models/fields/related_descriptors.py", line 189, in __get__
rel_obj = self.field.get_cached_value(instance)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/models/fields/mixins.py", line 15, in get_cached_value
return instance._state.fields_cache[cache_name]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'change'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/app/web/manage.py", line 30, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/loaddata.py", line 102, in handle
self.loaddata(fixture_labels)
File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/loaddata.py", line 163, in loaddata
self.load_label(fixture_label)
File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/loaddata.py", line 253, in load_label
if self.save_obj(obj):
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/loaddata.py", line 209, in save_obj
obj.save(using=self.using)
File "/usr/local/lib/python3.11/site-packages/django/core/serializers/base.py", line 288, in save
models.Model.save_base(self.object, using=using, raw=True, **kwargs)
File "/usr/local/lib/python3.11/site-packages/django/db/models/base.py", line 878, in save_base
post_save.send(
File "/usr/local/lib/python3.11/site-packages/django/dispatch/dispatcher.py", line 176, in send
return [
^
File "/usr/local/lib/python3.11/site-packages/django/dispatch/dispatcher.py", line 177, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/web/api_app/models.py", line 846, in set_change_updated_at
Change.objects.filter(pk=instance.change.pk).update(updated_at=instance.date)
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/models/fields/related_descriptors.py", line 207, in __get__
rel_obj = self.get_object(instance)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/models/fields/related_descriptors.py", line 170, in get_object
return qs.get(self.field.get_reverse_related_filter(instance))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/models/query.py", line 650, in get
raise self.model.DoesNotExist(
api_app.models.Change.DoesNotExist: Problem installing fixture '/home/app/web/stage_2023.04.05.json': Change matching query does not exist.
when restoring data with
python manage.py loaddata
an error is encountered saying,Change matching query does not exist
. The full error is shown at the bottom.This seems to be related to loaddata not loading models in order and and the post_save failing for Change objects.
This is may be a hacky fix, but to allow loaddata to run, an except has been added to the
set_change_updated_at
function.