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
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.9/site-packages/mypy_django_plugin/transformers/orm_lookups.py", line 31, in typecheck_queryset_filter
lookup_type = django_context.resolve_lookup_expected_type(ctx, model_cls, lookup_kwarg)
File "/Users/jacob/modularhistory/.venv/lib/python3.9/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.9/site-packages/django/db/models/sql/query.py", line 1052, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "/Users/jacob/modularhistory/.venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1484, in names_to_path
pathinfos = field.get_path_info(filtered_relation)
File "/Users/jacob/modularhistory/.venv/lib/python3.9/site-packages/django/db/models/fields/related.py", line 723, in get_path_info
opts = self.remote_field.model._meta
AttributeError: 'str' object has no attribute '_meta'
apps/trees/models.py:89: : note: use --pdb to drop into pdb
I did some debugging and found that when this 'str' object has no attribute '_meta' error happens, the value of self.remote_field is 'self'.
To Reproduce
Here's the abridged content of my models.py:
"""Based on https://github.com/peopledoc/django-ltree-demo."""
from typing import Type
from django.core.exceptions import ValidationError
from django.db.models.query import QuerySet
from django.utils.translation import ugettext_lazy as _
from core.models.model import Model
class TreeModel(Model):
"""Implements Postgres ltree for self-referencing hierarchy."""
parent = models.ForeignKey(
to='self',
null=True,
blank=True,
related_name='children',
on_delete=models.CASCADE,
verbose_name=_('parent'),
)
name = models.TextField(verbose_name=_('name'))
# https://docs.djangoproject.com/en/dev/ref/models/options/#model-meta-options
class Meta:
abstract = True
@property
def siblings(self) -> QuerySet['TreeModel']:
"""Return the model instances's siblings."""
# Here is where it fails:
return self.__class__.objects.exclude(id=self.id).filter(parent_id=self.parent_id)
The text was updated successfully, but these errors were encountered:
jacobjove
changed the title
Mypy crashes when it encounters Django ORM lookup traversing self-referencing m2m relationship
Mypy crashes when it encounters Django ORM lookup traversing self-referencing relationship
May 29, 2021
jacobjove
changed the title
Mypy crashes when it encounters Django ORM lookup traversing self-referencing relationship
Mypy crashes when it encounters Django ORM query with self-referencing relationship
May 29, 2021
Crash Report
(Tell us what happened.)
Traceback
I did some debugging and found that when this
'str' object has no attribute '_meta'
error happens, the value of self.remote_field is'self'
.To Reproduce
Here's the abridged content of my models.py:
The text was updated successfully, but these errors were encountered: