You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a manager is created using .from_queryset() and imported from another module, it's type is Any, but only when the QuerySet subclass has its generic specified as ["MyModel"].
What's wrong
I took this test case and adapted it to move the NewManager = BaseManager.from_queryset(ModelQuerySet) line into myapp/querysets.py and imported NewManager into myapp/models.py instead of ModelQuerySet.
As far as I could work out get_dynamic_class_hook is being called for myapp.models.NewManager, but then get_function_hook/get_method_hook doesn't seem to get called for methods on the manager in the failure case.
How is that should be
When NewManager is created using .from_queryset() and is imported from another module it shouldn't resolve to Any when Queryset["MyModel"] is used as the subclass, but should be the same as when only QuerySet is used as the subclass or NewManager is created in myapp/models.py.
System information
OS:
python version: 3.9.5
django version: 3.2.13
mypy version: 0.961
django-stubs version: 1.12.0
django-stubs-ext version: 0.5.0
The text was updated successfully, but these errors were encountered:
Hmm. Yes. And it also works if I do class ModelQuerySet(models.QuerySet["models.Model"]), so it's not specifically to do with string annotations. Most likely something to do with the circular dependency and the order things are resolved - maybe we need to defer for an extra pass somewhere?
Bug report
When a manager is created using
.from_queryset()
and imported from another module, it's type isAny
, but only when theQuerySet
subclass has its generic specified as["MyModel"]
.What's wrong
I took this test case and adapted it to move the
NewManager = BaseManager.from_queryset(ModelQuerySet)
line intomyapp/querysets.py
and importedNewManager
intomyapp/models.py
instead ofModelQuerySet
.See this diff: from_queryset-extra-tests.txt
Applying this to the current
master
results in the following two tests failing:from_queryset_using_basemanager_with_manager_imported_from_other_module
from_queryset_using_manager_with_manager_imported_from_other_module
If I change the following in
myapp/querysets.py
for these tests then they pass:Weird.
As far as I could work out
get_dynamic_class_hook
is being called formyapp.models.NewManager
, but thenget_function_hook
/get_method_hook
doesn't seem to get called for methods on the manager in the failure case.How is that should be
When
NewManager
is created using.from_queryset()
and is imported from another module it shouldn't resolve toAny
whenQueryset["MyModel"]
is used as the subclass, but should be the same as when onlyQuerySet
is used as the subclass orNewManager
is created inmyapp/models.py
.System information
python
version: 3.9.5django
version: 3.2.13mypy
version: 0.961django-stubs
version: 1.12.0django-stubs-ext
version: 0.5.0The text was updated successfully, but these errors were encountered: