-
-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash when constructing an abstract model with recursive relation #1393
Merged
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
31db97b
500 error when abstract model has a recursive relation
zuzelvp b307edf
Update context.py
zuzelvp 6631dfa
Update related.pyi
zuzelvp f85ceed
Update related.pyi
zuzelvp 9863587
Update related.pyi
zuzelvp dd747e3
Update test_related_fields.yml
zuzelvp 8d0300c
Update test_related_fields.yml
zuzelvp 4cb8652
Update helpers.py
zuzelvp bc34afb
Update context.py
zuzelvp 89359c7
Update context.py
zuzelvp 45ec040
Update reverse_related.pyi
zuzelvp 826baea
Update __init__.pyi
zuzelvp e0d25f7
Update __init__.pyi
zuzelvp fd92e04
Update test_related_fields.yml
zuzelvp fb92aec
Add breaking test with abstract model having recursive relation
flaeppe 05a60ee
Pick up to/target model from `field.remote_field.model` attribute
flaeppe dd63e76
Merge branch 'master' into zuzelvp-patch-1
flaeppe 4d0c0d8
Update expected error messages when instantiating abstract model
flaeppe ab848eb
Update mypy_django_plugin/lib/helpers.py
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the curious one; it was initialisation of an abstract model(i.e. this line) that raised the error seen in the provided traceback |
||
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): | ||
... |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main portion of the fix. The rest was trying to get typing to work now that model_cls can be a string.