-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make plugin handle explicitly declared reverse descriptors for FKs (#…
…2230) * Make plugin handle explicitly declared reverse descriptors for FKs If a reverse descriptor was explicitly declared on a model, the plugin skipped to create a more specific subclass for its related manager. * fixup! Make plugin handle explicitly declared reverse descriptors for FKs
- Loading branch information
Showing
3 changed files
with
75 additions
and
25 deletions.
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
18 changes: 18 additions & 0 deletions
18
tests/assert_type/db/models/fields/test_related_descriptors.py
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import ClassVar | ||
|
||
from django.db import models | ||
from django.db.models.fields.related_descriptors import RelatedManager, ReverseManyToOneDescriptor | ||
from typing_extensions import assert_type | ||
|
||
|
||
class Other(models.Model): | ||
explicit_descriptor: ClassVar[ReverseManyToOneDescriptor["MyModel"]] | ||
|
||
|
||
class MyModel(models.Model): | ||
rel = models.ForeignKey[Other, Other](Other, on_delete=models.CASCADE, related_name="explicit_descriptor") | ||
|
||
|
||
# Pyright doesn't allow "runtime" usage of @type_check_only 'RelatedManager' but we're | ||
# only type checking these files so it should be fine. | ||
assert_type(Other().explicit_descriptor, RelatedManager[MyModel]) # pyright: ignore[reportGeneralTypeIssues] |
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