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

Cannot resolve manager type when using django-polymorphic #1158

Open
AntoineRondelet opened this issue Sep 20, 2022 · 4 comments
Open

Cannot resolve manager type when using django-polymorphic #1158

AntoineRondelet opened this issue Sep 20, 2022 · 4 comments
Labels
3rd party Presence of a third party dependency has been mentioned bug Something isn't working mypy-plugin Issues specific to mypy_django_plugin

Comments

@AntoineRondelet
Copy link

Bug report

Hi, I'm not sure if this is a genuine bug or if I am just doing something wrong.
I recently used django-polymorphic to add a new feature in my project and mypy is now breaking. I have plenty of errors:

error: Could not resolve manager type for "<MyModel>.objects"

and

error: Couldn't resolve related manager for relation '<related_name>'

After checking the django polymorphic docs: https://django-polymorphic.readthedocs.io/en/stable/managers.html#manager-inheritance I can see that the manager is inherited. Could that be the source of mypy's troubles here? I feel it could be, but I'd be happy to get opinions.

Is that a known issue with django-polymorphic that I simply am not aware of? If so, is there a (concise) way around it? If not, I'll probably fallback to the "multiple FK in a model" approach to keep mypy running...

Happy to hear if I'm missing something obvious!
Thanks in advance! :)

System information

  • OS: macOS Monterey 12.6
  • python version: 3.10.6
  • django version: 4.1
  • mypy version: 0.971
  • django-stubs version: 1.12.0
  • django-stubs-ext version: 0.5.0
@AntoineRondelet AntoineRondelet added the bug Something isn't working label Sep 20, 2022
@AntoineRondelet
Copy link
Author

To add to this, here's basically what I'm doing:

class Thing(PolymorphicModel):

    id = models.UUIDField(
        default=uuid.uuid4, unique=True, primary_key=True, editable=False
    )

    created = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ["-created"]

I then use this in another module

class SpecificThing(Thing):

    text = models.CharField(max_length=10)

and I define explicit through models for relationships

class SpecificThingRelationship(models.Model):

    source = models.ForeignKey(User, on_delete=models.CASCADE, related_name="things")
    target = models.ForeignKey(SpecificThing, on_delete=models.CASCADE, related_name="users")

@AntoineRondelet
Copy link
Author

May be related to #1023

@sterliakov
Copy link
Contributor

CC: https://stackoverflow.com/questions/73866986/cannot-resolve-manager-type-when-using-django-polymorphic-with-mypy-django-stubs

@intgr intgr added the mypy-plugin Issues specific to mypy_django_plugin label Nov 8, 2022
@jose-reveni
Copy link

Is there any known workaround for this? I've tried disabling the django-manager-missing error code in mypy but that doesn't work (python/mypy#12987), so I'm stuck using v0.950 :(

Also, I think this issue might be a duplicate of #1023

@flaeppe flaeppe added the 3rd party Presence of a third party dependency has been mentioned label Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party Presence of a third party dependency has been mentioned bug Something isn't working mypy-plugin Issues specific to mypy_django_plugin
Development

No branches or pull requests

5 participants