Skip to content

Commit

Permalink
Add breaking test with abstract model having recursive relation
Browse files Browse the repository at this point in the history
  • Loading branch information
flaeppe committed Jul 11, 2023
1 parent fd92e04 commit fb92aec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 25 additions & 0 deletions tests/typecheck/models/test_abstract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,28 @@
class MyModel(BaseModel):
field = models.IntegerField()
- case: test_can_instantiate_with_recursive_relation_on_abstract_model
main: |
from myapp.models import Concrete, Recursive
first = Concrete.objects.create(parent=None)
Concrete.objects.create(parent=first)
Recursive.objects.create(parent=None)
Recursive(parent=Recursive(parent=None)) # E: Unexpected attribute "parent" for model "Recursive"
Concrete(parent=Concrete(parent=None))
installed_apps:
- myapp
files:
- path: myapp/__init__.py
- path: myapp/models.py
content: |
from django.db import models
class Recursive(models.Model):
parent = models.ForeignKey("self", null=True, on_delete=models.CASCADE)
class Meta:
abstract = True
class Concrete(Recursive):
...
2 changes: 0 additions & 2 deletions tests/typecheck/models/test_related_fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
reveal_type(Model2().test) # N: Revealed type is "app3.models.Model3_RelatedManager"
reveal_type(Model1().test2) # N: Revealed type is "app3.models.Model4_RelatedManager"
reveal_type(Model2().test2) # N: Revealed type is "app3.models.Model4_RelatedManager"
Model1()
installed_apps:
- base
- users
Expand All @@ -21,7 +20,6 @@
from django.db import models
class OwnedModel(models.Model):
owner = models.ForeignKey("users.User", on_delete=models.CASCADE)
myself = models.ForeignKey("self", on_delete=models.CASCADE)
class Meta:
abstract = True
Expand Down

0 comments on commit fb92aec

Please sign in to comment.