Skip to content

Commit

Permalink
Add explicit test for .from_quertset Any fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Jun 17, 2022
1 parent 023106f commit 4ea9b87
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/typecheck/fields/test_related.yml
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,37 @@
Transaction().test()
- case: foreign_key_relationship_for_models_with_custom_manager_unsolvable
main: |
from myapp.models import Transaction
installed_apps:
- myapp
files:
- path: myapp/__init__.py
- path: myapp/models.py
content: |
from django.db import models
from django.db.models.manager import BaseManager
class TransactionQuerySet(models.QuerySet):
def custom(self) -> None:
pass
# Note, that we cannot resolve dynamic calls for custom managers:
class Transaction(models.Model):
objects = BaseManager.from_queryset(TransactionQuerySet)
def test(self) -> None:
reveal_type(self.transactionlog_set)
# We use a fallback Any type:
reveal_type(Transaction.objects.custom())
class TransactionLog(models.Model):
transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE)
out: |
myapp/models:9: error: `.from_queryset` called from inside model class body
myapp/models:11: note: Revealed type is "django.db.models.manager.RelatedManager[myapp.models.TransactionLog]"
myapp/models:13: note: Revealed type is "Any"
- case: resolve_primary_keys_for_foreign_keys_with_abstract_self_model
main: |
from myapp.models import User
Expand Down

0 comments on commit 4ea9b87

Please sign in to comment.