Skip to content

FieldTracker.finalize_class raises AttributeError when used with django-positions PositionField #579

@iarp

Description

@iarp

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions