We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
select_related breaks custom managers.
select_related
Take the following example:
class TransactionQuerySet(models.QuerySet): def with_status(self): return self.filter(status=...) class TransactionManager(models.Manager): def get_queryset(self) -> TransactionQuerySet: return TransactionQuerySet(self.model, using=self._db) def with_status(self): return self.get_queryset().with_status() class Transaction(models.Model): ... objects = TransactionManager()
The following code has no type errors:
Transaction.objects.with_status()
But the following fails:
Transaction.objects.select_related().with_status() error: "_QuerySet[Transaction, Transaction]" has no attribute "with_status"
The revealed types:
reveal_type(Transaction.objects) reveal_type(Transaction.objects.select_related()) note: Revealed type is "core.core.models.Transaction_TransactionManager5[core.core.models.Transaction]" note: Revealed type is "django.db.models.query._QuerySet[core.core.models.Transaction*, core.core.models.Transaction*]"
This problem started after I updated django-stubs from 1.8.0 to 1.9.0
python
django
mypy
django-stubs
django-stubs-ext
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug report
What's wrong
select_related
breaks custom managers.Take the following example:
The following code has no type errors:
But the following fails:
The revealed types:
This problem started after I updated django-stubs from 1.8.0 to 1.9.0
System information
python
version: 3.9.7django
version: 3.2.8mypy
version: 0.910django-stubs
version: 1.9.0django-stubs-ext
version: Not using itThe text was updated successfully, but these errors were encountered: