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
Looks like the transformer for ManyToManyField doesn't handle the case for when the related model passed in is aliased. The to model is still typed properly, since it's inferred and returned as the FunctionContext default_return_type, but any generated through model is never typed.
Example:
from django.contrib.auth import models as auth_models
from django.db import models
class MyModel(models.Model):
allowed_groups = models.ManyToManyField(auth_models.Group)
MemberExpr:11(
NameExpr(auth_models [django.contrib.auth.models])
Group [django.contrib.auth.models.Group])
But this case is only handled explicitly for the django.contrib.auth.models.User model. In other cases, it returns None, and the transform for the whole field just returns the default value.
How is that should be
Since normal RelatedFields resolve their related models fine with aliased imports, it seems the manytomany transformer should be able to use the same logic (a la django_context.get_field_related_model_cls(current_field)) for resolving both its to and through models. Though I'm sure there's some complexities around how Django models m2m relations that would require some changes from how get_field_related_model_cls works.
System information
OS:
python version: 3.8
django version: 4.2.9
mypy version: 1.10
django-stubs version: 5.0
django-stubs-ext version:
The text was updated successfully, but these errors were encountered:
Bug report
What's wrong
Looks like the transformer for ManyToManyField doesn't handle the case for when the related model passed in is aliased. The
to
model is still typed properly, since it's inferred and returned as the FunctionContextdefault_return_type
, but any generatedthrough
model is never typed.Example:
I believe
get_model_from_expression()
gets passed a MemberExpr as such:But this case is only handled explicitly for the django.contrib.auth.models.User model. In other cases, it returns None, and the transform for the whole field just returns the default value.
How is that should be
Since normal RelatedFields resolve their related models fine with aliased imports, it seems the manytomany transformer should be able to use the same logic (a la
django_context.get_field_related_model_cls(current_field)
) for resolving both itsto
andthrough
models. Though I'm sure there's some complexities around how Django models m2m relations that would require some changes from howget_field_related_model_cls
works.System information
python
version: 3.8django
version: 4.2.9mypy
version: 1.10django-stubs
version: 5.0django-stubs-ext
version:The text was updated successfully, but these errors were encountered: