Skip to content

Problem with manager created using .from_queryset() and imported from other module #1032

@ngnpope

Description

@ngnpope

Bug report

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.

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:

-                class ModelQuerySet(models.QuerySet["MyModel"]):
+                class ModelQuerySet(models.QuerySet):

Weird.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions