Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: ... object has no attribute '_tracker' #574

Open
rrauenza opened this issue Jun 14, 2023 · 1 comment
Open

AttributeError: ... object has no attribute '_tracker' #574

rrauenza opened this issue Jun 14, 2023 · 1 comment

Comments

@rrauenza
Copy link

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.

@rrauenza
Copy link
Author

rrauenza commented Jun 14, 2023

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant