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

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

Open
iarp opened this issue Aug 13, 2023 · 0 comments

Comments

@iarp
Copy link

iarp commented Aug 13, 2023

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)
@iarp iarp changed the title FieldTracker.finalize_class raises AttributeError when used with PositionField FieldTracker.finalize_class raises AttributeError when used with django-positions PositionField Aug 13, 2023
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