django-stubs
django-stubs copied to clipboard
Cannot resolve manager type when using django-polymorphic
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
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")
May be related to https://github.com/typeddjango/django-stubs/issues/1023
CC: https://stackoverflow.com/questions/73866986/cannot-resolve-manager-type-when-using-django-polymorphic-with-mypy-django-stubs
Is there any known workaround for this? I've tried disabling the django-manager-missing
error code in mypy but that doesn't work (https://github.com/python/mypy/issues/12987), so I'm stuck using v0.950 :(
Also, I think this issue might be a duplicate of https://github.com/typeddjango/django-stubs/issues/1023