typeddjango / django-stubs

PEP-484 stubs for Django
MIT License
1.61k stars 452 forks source link

Could not resolve manager for abstract model subclasses #1157

Open PyB1l opened 2 years ago

PyB1l commented 2 years ago

Bug report

It seem we get an weird behavior on custom manager when subclassing an abstract model defined on another module.

What's wrong

Following the official suggestions I have:

# module A

class MyQuerySet(models.Queryset):
    # my methods

MyManager = models.Manager.from_queryset(MyQuerySet)

class BaseModel(models.Model):
    # model fields
    objects = MyManager()

# On module B

from module_a import BaseModel

class MyModel(BaseModel)
    # more fields

On the initial run and presuming I have no other error everything works fine. With any code change I get errors Could not resolve manager type for "module_b.MyModel".

The weird thing is that if I erase the .mypy_cache dir mypy want complain, but again on every code change the errors get back.

System information

flaeppe commented 2 years ago

This sounds a bit similar to #1151