Skip to content

Commit

Permalink
Test usage of from_queryset manager as reverse manager (#2295)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaeppe authored Jul 30, 2024
1 parent b6b4353 commit 6667440
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/typecheck/managers/querysets/test_from_queryset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,25 @@
main:12: error: Argument 1 to "from_queryset" of "BaseManager" has incompatible type "<typing special form>"; expected "Type[QuerySet[Model, Model]]" [arg-type]
main:17: note: Revealed type is "Type[django.db.models.manager.Manager[django.db.models.base.Model]]"
main:17: error: Argument 1 to "from_queryset" of "BaseManager" has incompatible type "Type[NonQSGeneric[Any]]"; expected "Type[QuerySet[Model, Model]]" [arg-type]
- case: test_reverse_manager_with_foreign_key
main: |
from myapp.models import B
reveal_type(B().a_set.filter(field="something")) # N: Revealed type is "myapp.models.QS"
installed_apps:
- myapp
files:
- path: myapp/__init__.py
- path: myapp/models.py
content: |
from django.db import models
class B(models.Model): ...
class QS(models.QuerySet["A"]): ...
Manager = models.Manager.from_queryset(QS)
class A(models.Model):
field = models.CharField()
b = models.ForeignKey(B, on_delete=models.CASCADE)
objects = Manager()

0 comments on commit 6667440

Please sign in to comment.