mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 14:01:56 +08:00
Add explicit test for .from_quertset Any fallback
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user