django-stubs icon indicating copy to clipboard operation
django-stubs copied to clipboard

AssertionError on Union with custom QuerySet/Manager

Open ljodal opened this issue 3 years ago • 0 comments

Bug report

What's wrong

Mypy crashes with an assertion error if a variable has a union type of two different, custom querysets. I have a branch with a test case to reproduce the issue here. I haven't had time to look at fixing this yet, but I think it's a simple case of adding support for this case.

Traceback (most recent call last):
  File "mypy/checkexpr.py", line 3978, in accept
  File "mypy/nodes.py", line 1670, in accept
  File "mypy/checkexpr.py", line 2087, in visit_member_expr
  File "mypy/checkexpr.py", line 2105, in analyze_ordinary_member_access
  File "mypy/checkmember.py", line 130, in analyze_member_access
  File "mypy/checkmember.py", line 152, in _analyze_member_access
  File "mypy/checkmember.py", line 320, in analyze_union_member_access
  File "mypy/checkmember.py", line 147, in _analyze_member_access
  File "mypy/checkmember.py", line 231, in analyze_instance_member_access
  File "mypy/checkmember.py", line 385, in analyze_member_var_access
  File "mypy/checkmember.py", line 614, in analyze_var
  File "/Users/sigurd/Developer/django-stubs/mypy_django_plugin/transformers/managers.py", line 114, in resolve_manager_method
    assert isinstance(manager_instance, Instance)

How is that should be

It should correctly resolve the type or complain if one of the union types are missing the method. Alternatively it could fall back to Any for now.

System information

  • OS:
  • python version: 3.9.10
  • django version: 3.2.12
  • mypy version: 0.942
  • django-stubs version: latest master
  • django-stubs-ext version: latest master

ljodal avatar Apr 01 '22 08:04 ljodal