-
-
Notifications
You must be signed in to change notification settings - Fork 481
Fix missing related managers on some models #902
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
Merged
sobolevn
merged 3 commits into
typeddjango:master
from
ljodal:fix-missing-related-managers
Mar 31, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
- case: test_related_name_custom_manager | ||
main: | | ||
from app1.models import Model1 | ||
from app2.models import Model2 | ||
|
||
reveal_type(Model1().test) # N: Revealed type is "app3.models.Model3_RelatedManager" | ||
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" | ||
installed_apps: | ||
- base | ||
- users | ||
- app1 | ||
- app2 | ||
- app3 | ||
files: | ||
- path: base/__init__.py | ||
- path: base/models.py | ||
content: | | ||
from django.db import models | ||
class OwnedModel(models.Model): | ||
owner = models.ForeignKey("users.User", on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
- path: users/__init__.py | ||
- path: users/models.py | ||
content: | | ||
from django.db import models | ||
class User(models.Model): | ||
pass | ||
|
||
- path: app1/__init__.py | ||
- path: app1/models.py | ||
content: | | ||
from django.db import models | ||
from base.models import OwnedModel | ||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from app3.models import Model3 | ||
|
||
class CustomQuerySet(models.QuerySet): | ||
pass | ||
|
||
Model1Manager = models.Manager.from_queryset(CustomQuerySet) | ||
class Model1(OwnedModel): | ||
objects = Model1Manager() | ||
|
||
- path: app2/__init__.py | ||
- path: app2/models.py | ||
content: | | ||
from django.db import models | ||
from base.models import OwnedModel | ||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from app3.models import Model3 | ||
|
||
class CustomQuerySet(models.QuerySet): | ||
pass | ||
|
||
Model2Manager = models.Manager.from_queryset(CustomQuerySet) | ||
class Model2(OwnedModel): | ||
objects = Model2Manager() | ||
|
||
- path: app3/__init__.py | ||
- path: app3/models.py | ||
content: | | ||
from django.db import models | ||
from app1.models import Model1 | ||
from app2.models import Model2 | ||
from base.models import OwnedModel | ||
|
||
class CustomQuerySet(models.QuerySet): | ||
pass | ||
|
||
Model3Manager = models.Manager.from_queryset(CustomQuerySet) | ||
class Model3(OwnedModel): | ||
a = models.ForeignKey(Model1, related_name="test", on_delete=models.CASCADE) | ||
b = models.ForeignKey(Model2, related_name="test", on_delete=models.CASCADE) | ||
|
||
objects = Model3Manager() | ||
|
||
Model4Manager = models.Manager.from_queryset(CustomQuerySet) | ||
class Model4(OwnedModel): | ||
a = models.ForeignKey(Model1, related_name="test2", on_delete=models.CASCADE) | ||
b = models.ForeignKey(Model2, related_name="test2", on_delete=models.CASCADE) | ||
|
||
objects = Model4Manager() |
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.
Without the fix these attributes will be missing, as it returns after adding the
.test
attributes