-
-
Notifications
You must be signed in to change notification settings - Fork 444
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
Model.<related_name>
has no attribute "through"
#1800
Comments
Hi! Did you configure mypy to use the |
I have this in
|
And does the |
It does, yes. (otherwise pretty much nothing would work :) ) |
I can reproduce this in django-stubs/tests/typecheck/fields/test_related.yml Lines 1070 to 1095 in 25e23fa
- case: test_many_to_many
main: |
from myapp.models import MyModel, Other
...
reveal_type(MyModel.other_again.through)
+ reveal_type(Other.autos.through) |
I think we need to improve with descriptor types here. e.g. reveal_type(Other.autos) # Revealed type is "django.db.models.manager.RelatedManager[myapp.models.MyModel]"
print(type(Other.autos)) # <class 'django.db.models.fields.related_descriptors.ManyToManyDescriptor'> |
I am still getting this error with |
@superlevure feel free to provide a breaking case and/or open a new issue |
Bug report
What's wrong
I confess, I am quite new to typing, so if this is a mypy issue and not a django-stubs issue, I apologise. I think I am reporting this in the right place though.
I have a ManyToManyField on a model:
And a
TabularInline
in admin for theIdentifier
model:But mypy does not like this :
How is that should be
No error should be raised because
Identifier.posts.through
is validSystem information
Linux LMAVSURFACE4 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
python
version: 3.11django
version: 4.2.6mypy
version: 1.6.1mypy-extensions
version: 1.0.0django-stubs
version: 4.2.5django-stubs-ext
version: 4.2.5The text was updated successfully, but these errors were encountered: