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 crashes when it encounters a Django ORM query that uses .exclude(pk=...).
For example:
@property
def ancestors(self) -> QuerySet:
"""Return the model instances's ancestors, based on its LTree field."""
return self.__class__.objects.exclude(pk=self.pk).filter(
path__descendant=self.path # custom lookup
)
@property
def descendants(self) -> QuerySet:
"""Return the model instances's descendants, based on its LTree field."""
return self.__class__.objects.exclude(pk=self.pk).filter(
path__ancestor=self.path # custom lookup
)
Traceback
version: 0.812
Traceback (most recent call last):
File "mypy/checkexpr.py", line 3898, in accept
File "mypy/nodes.py", line 1555, in accept
File "mypy/checkexpr.py", line 270, in visit_call_expr
File "mypy/checkexpr.py", line 347, in visit_call_expr_inner
File "mypy/checkexpr.py", line 852, in check_call_expr_with_callee_type
File "mypy/checkexpr.py", line 911, in check_call
File "mypy/checkexpr.py", line 1023, in check_callable_call
File "mypy/checkexpr.py", line 732, in apply_function_plugin
File "/Users/jacob/modularhistory/.venv/lib/python3.7/site-packages/mypy_django_plugin/transformers/orm_lookups.py", line 32, in typecheck_queryset_filter
lookup_type = django_context.resolve_lookup_expected_type(ctx, model_cls, lookup_kwarg)
File "/Users/jacob/modularhistory/.venv/lib/python3.7/site-packages/mypy_django_plugin/django/context.py", line 335, in resolve_lookup_expected_type
lookup_parts, field_parts, is_expression = query.solve_lookup_type(lookup)
File "/Users/jacob/modularhistory/.venv/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1084, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "/Users/jacob/modularhistory/.venv/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1442, in names_to_path
name = opts.pk.name
AttributeError: 'NoneType' object has no attribute 'name'
Your Environment
Mypy version used: 0.812
Mypy configuration options from mypy.ini (and other config files):
jacobjove
changed the title
Mypy crashes upon encountering custom Django ORM lookups
Mypy crashes upon encountering Django ORM query with .exclude(pk=...)May 29, 2021
Crash Report
Mypy crashes when it encounters a Django ORM query that uses
.exclude(pk=...)
.For example:
Traceback
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: