-
-
Notifications
You must be signed in to change notification settings - Fork 480
"RelatedModel" has no attribute "RelatedObjectDoesNotExist" [attr-defined] #1390
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
Comments
Hi. This was caused by #1309, which removes re-exports that are not part of Django's intentional public API. According to Django documentation https://docs.djangoproject.com/en/4.1/ref/exceptions/ the exception |
Alright, that's valid. The second prat of the bug report still applies. |
Ah sorry I missed the second part. You're right, that's a bug. Looks like it could be complicated. |
Hey! @eternal-sorrow can you share the code snippet in which you encountered the bug? On a quick lookup in django-stubs/django-stubs/db/models/fields/related_descriptors.pyi Lines 19 to 34 in 0aa7bf1
django-stubs/django-stubs/db/models/fields/related_descriptors.pyi Lines 40 to 52 in 0aa7bf1
One thing that I think that might be causing the issue can be the fact that the |
class A(models.Model):
...
class B(models.Model):
a = models.OneToOneField(A, related_name='b')
a = A.objects.first()
try:
b = a.b
except A.b.RelatedObjectDoesNotExist: # mypy complains here '"B" has no attribute "RelatedObjectDoesNotExist"'
pass |
Closed via #1733 |
Bug report
What's wrong
Mypy printsModule "django.db.models" has no attribute "ObjectDoesNotExist" [attr-defined]
on thefrom django.db.models import ObjectDoesNotExist
line, which is obviously wrong.Also, if I alternatively use
MyModel.field.RelatedObjectDoesNotExist
, I get the"RelatedModel" has no attribute "RelatedObjectDoesNotExist" [attr-defined]
message.field
here is a reverse relation fromRelatedModel
toMyModel
one-to-one field.How is that should be
No error messages.
System information
python
version: 3.10.6django
version: 3.2.18mypy
version: 1.0.1django-stubs
version: 1.15.0django-stubs-ext
version: 0.7.0The text was updated successfully, but these errors were encountered: