You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mypy cannot detect the through attribute of a ManyToManyField within the definition of the enclosing model. To reproduce, add the following test method to MyModel in tests/typecheck/fields/test_related.yml::test_many_to_many:
classMyModel(models.Model):
auto_through=models.ManyToManyField(Other, related_name="autos")
# Have multiple M2Ms with implicit throughother_again=models.ManyToManyField(Other, related_name="others_again")
custom_through=models.ManyToManyField(Other, through=CustomThrough, related_name="customs")
objects=MyModelManager()
deftest(self) ->None:
reveal_type(self.custom_through.through)
Results in:
myapp/models/__init__:31: error: "Other_ManyRelatedManager" has no attribute "through" [attr-defined]
myapp/models/__init__:31: note: Revealed type is "Any"
How is that should be
Revealed type should be "CustomThrough"
System information
OS: macOS 14.2.1
python version: 3.12.1
django version: 4.2.9
mypy version: 1.7.1
django-stubs version: 4.2.7
django-stubs-ext version: 4.2.7
The text was updated successfully, but these errors were encountered:
Bug report
What's wrong
Mypy cannot detect the
through
attribute of aManyToManyField
within the definition of the enclosing model. To reproduce, add the following test method toMyModel
intests/typecheck/fields/test_related.yml::test_many_to_many
:Results in:
How is that should be
Revealed type should be
"CustomThrough"
System information
python
version: 3.12.1django
version: 4.2.9mypy
version: 1.7.1django-stubs
version: 4.2.7django-stubs-ext
version: 4.2.7The text was updated successfully, but these errors were encountered: