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: 'DescriptorWrapper' object has no attribute 'get_queryset' #508

Open
al-muammar opened this issue Nov 10, 2021 · 3 comments

Comments

@al-muammar
Copy link

Problem

When accessing model's field, DescriptorWrapper returns itself as an object, which breaks the logic. See more in examples.

Environment

  • Django Model Utils version: 4.1.1
  • Django version: 3.2.8
  • Python version: 3.9.1
  • Other libraries used, if any:

Code examples

class A(models.Model):
    pass

class B(models.Model):
    x = models.ForeignKey(A, on_delete=models.CASCADE)

    tracker = FieldTracker(fields=["x"])

# This throws
B.x.get_queryset()
@stevelacey
Copy link

stevelacey commented Mar 29, 2022

Also happens with B.x.field, the wrapper breaks anything that introspects models

@stevelacey
Copy link

This works fwiw

from model_utils.tracker import DescriptorWrapper

@property
def field(self):
    return self.descriptor.field

@property
def get_queryset(self):
    return self.descriptor.get_queryset

DescriptorWrapper.field = field
DescriptorWrapper.get_queryset = get_queryset

@stevelacey
Copy link

stevelacey commented Mar 31, 2022

I am really not sure what's going on with DescriptorWrapper or why it doesn't quack like a duck if it's wrapping fields.

I am kind of surprised this doesn't cause more issues, you'd think lots of things would access .field.

@lucaswiman any suggestions? would this be a reasonable addition to DescriptorWrapper?

    def __getattr__(self, attr):
        return getattr(self.descriptor, attr)

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

2 participants