FieldTracker.finalize_class raises AttributeError when used with django-positions PositionField
iarp opened this issue · 0 comments
iarp commented
Problem
Using django-positions PositionField
on the model. Adding tracker = FieldTracker()
causes the following exception to run at runtime preventing the server from starting
File "F:\Projects\myproj\venv\lib\site-packages\model_utils\tracker.py", line 338, in finalize_class
descriptor = getattr(sender, field_name)
File "F:\Projects\myproj\venv\lib\site-packages\positions\fields.py", line 144, in __get__
raise AttributeError("%s must be accessed via instance." % self.name)
AttributeError: display_order must be accessed via instance.
PositionField.__get__
raises AttributeError if you attempt to getattr on its field as seen here https://github.com/jpwatts/django-positions/blob/master/positions/fields.py#L142
I was able to fix this by changing FieldTrackers use of descriptor = getattr(sender, field_name)
to descriptor = getattr(sender, field_name, None)
I'm unsure which package should be the one to update though.
Environment
- Django Model Utils version: 4.3.1
- Django version: 4.2.4
- Python version: 3.10.7
- Other libraries used, if any:
- django-positions 0.6.0
Code examples
class PlaylistItem(models.Model):
field_tracker = FieldTracker()
display_order = PositionField(default=-1)