diff --git a/tests/typecheck/fields/test_related.yml b/tests/typecheck/fields/test_related.yml index 11a8c60da..af416c79f 100644 --- a/tests/typecheck/fields/test_related.yml +++ b/tests/typecheck/fields/test_related.yml @@ -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