AttributeError: ... object has no attribute '_tracker'
rrauenza opened this issue · 1 comments
Problem
I'm getting the following stack trace and I'm not sure why. It seems like such a simple case -- just creating an object.
Traceback (most recent call last):
[...]
File ".../testing/mock_data.py", line 194, in _add_run
run = Run.objects.create(
^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.11/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.11/site-packages/django/db/models/query.py", line 453, in create
obj.save(force_insert=True, using=self.db)
File ".../models/run.py", line 127, in save
super().save(*args, **kwargs)
File ".../.venv/lib/python3.11/site-packages/django/db/models/base.py", line 739, in save
self.save_base(using=using, force_insert=force_insert,
File ".../.venv/lib/python3.11/site-packages/model_utils/tracker.py", line 373, in inner
tracker = getattr(instance, self.attname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Run' object has no attribute '_tracker'
Removing my own save() didn't help
The class is derived directly from models.Model and tracker = FieldTracker() is after all of the fields.
Is there any other debugging or tracing I could provide to show why _tracker isn't added to the class?
Environment
- Django Model Utils version: 4.3.1
- Django version: 3.2.19
- Python version: 3.11
- Other libraries used, if any:
Code examples
Give code example that demonstrates the issue, or even better, write new tests that fails because of that issue.
I'm going to try some tracing to provide more info.
Aha!.... I turn off signals in some of my unit tests to speed up tests when my object factory is running.
Anyone else googling and finding this error, it's likely you've disabled signals.
Will leave open in case team wants to call this out in the docs? (actually, it looks like this is implicitly mentioned in the implementation details.)