-
-
Notifications
You must be signed in to change notification settings - Fork 521
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Bug report
What's wrong
When defining managers with a custom queryset, the typing of said queryset is lost. Instead of having MyQuerySet we have QuerySet[MyModel, MyModel].
This happens whether the manager is created manually, or using Manager.from_queryset(...)
from django.db import models
class MyQuerySet(models.QuerySet):
pass
class MyManager(models.Manager):
def get_queryset(self) -> MyQuerySet:
return MyQuerySet(self.model, using=self._db)
class MyModel(models.Model):
objects_my_manager = MyManager()
objects_from_queryset = models.Manager.from_queryset(MyQuerySet)()
reveal_type(MyModel.objects_my_manager.all()) # Revealed type is "QuerySet[MyModel, MyModel]"
reveal_type(MyModel.objects_from_queryset.all()) # Revealed type is "QuerySet[MyModel, MyModel]"How is that should be
I would like all manager methods that return a queryset (.all(), .filter(...), .only(...) ....) to return MyQuerySet.
We are currently using a workaround very similar to the one described here #863
System information
- OS: Ubuntu 22.04.5 LTS
pythonversion: 3.11.12djangoversion: 4.2.11mypyversion: 1.15.0django-stubsversion: 5.1.3django-stubs-extversion: 5.1.3
jacek-rybak, fabien-michel, sshishov, UnknownPlatypus, heinrichf-cdgnm and 1 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working