-
-
Notifications
You must be signed in to change notification settings - Fork 450
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
mypy crashes with KeyError: 'django_stubs_ext' when using django-stubs 1.9.0 #701
Comments
Please, check that |
Forgot to mention that, |
Just to double check: |
I would also highly appreciate a simple reproduction. In this case I will be able to fix this today / during weekend. |
Yes it is running with 0.3.0. I'll try to replicate it with a barebones project and post the steps here. |
OK, apparently, (might be because of newer mypy version, 0.910), my This too happened with a barebones Django project. Closing this issue. |
Ok, thanks a lot! If this happens again - I will add this to the docs. |
Same here. Downgrade to 1.8.0 helped. Will try to investigate what's wrong. |
Previous error raises for python 3.9. For 3.10 it's different:
Feels like something's wrong with types of annotated queryset: without |
Looks like a |
I would love to fix it with a proper reproduction. |
@sobolevn I've tried to create a minimal django app to reproduce. See https://github.com/sidmitra/django-stubs-issue Also see the github failed github action with the mypy traceback: ./stubissue/fake_issue.py:9: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.910
./stubissue/fake_issue.py:9: : note: use --pdb to drop into pdb
Traceback (most recent call last):
File "mypy/checkexpr.py", line 3911, in accept
File "mypy/nodes.py", line 1558, in accept
File "mypy/checkexpr.py", line 271, in visit_call_expr
File "mypy/checkexpr.py", line 353, in visit_call_expr_inner
File "mypy/checkexpr.py", line 858, in check_call_expr_with_callee_type
File "mypy/checkexpr.py", line 917, in check_call
File "mypy/checkexpr.py", line 1029, in check_callable_call
File "mypy/checkexpr.py", line 738, in apply_function_plugin
File "/tmp/venv/lib/python3.9/site-packages/mypy_django_plugin/transformers/querysets.py", line 231, in extract_proper_type_queryset_annotate
annotated_type = get_or_create_annotated_type(api, model_type, fields_dict=fields_dict)
File "/tmp/venv/lib/python3.9/site-packages/mypy_django_plugin/transformers/models.py", line 447, in get_or_create_annotated_type
model_module_file = api.modules[model_module_name] # type: ignore
KeyError: 'django_stubs_ext' Note that this only happens with 1.9.0v of django-stubs, but not 1.8.0, so it's holding up an upgrade. I'll try to dig deeper this week, but not very familiar with the new django-stubs-ext stuff. Even if type annotation with queryset annotate() + Count() is not possible, it might still be workable if i can just |
AWESOME! Thanks a lot. |
This issue might be somewhat related(or the same root cause): #745 Just adding a reference to link both. |
I updated my project to reproduce this with the latest mypy and git master branch for django-stubs. This error still seems to be present. https://github.com/sidmitra/django-stubs-issue/runs/6951208566?check_suite_focus=true
|
This worked for me
from django.db.models import QuerySet
class FooQuerySet(QuerySet):
pass
from django.db.models import Model, Manager
class Foo(Model):
...
objects = Manager.from_queryset(FooQuerySet)() |
Bug report
mypy crashes when reaching code with Django queries that annotate fields, which did not happen which django-stubs version 1.8.0.
What's wrong
How is that should be
I Just upgraded from 1.8.0 to 1.9.0, and it was working without errors before upgrading.
System information
python
version: 3.9.1django
version: 3.2.7mypy
version: 0.910django-stubs
version: 1.9.0The text was updated successfully, but these errors were encountered: