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

Custom User model raises INTERNAL ERROR

Open thinkwelltwd opened this issue 1 year ago • 4 comments

Bug report

I'm adding type hints to a rather large Django project with a custom user model, discovered a bug after upgrading to Django 5.1.4.

What's wrong

$ mypy --show-traceback apps/app-name
/usr/local/lib/python3.12/dist-packages/django-stubs/http/request.pyi:58: 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: 1.13.0
Traceback (most recent call last):
  File "mypy/semanal.py", line 7113, in accept
  File "mypy/nodes.py", line 1351, in accept
  File "mypy/semanal.py", line 3153, in visit_assignment_stmt
  File "mypy/semanal.py", line 3671, in process_type_annotation
  File "mypy/semanal.py", line 6767, in defer
AssertionError: Must not defer during final iteration
/usr/local/lib/python3.12/dist-packages/django-stubs/http/request.pyi:58: : note: use --pdb to drop into pdb

How it should be

I've narrowed the problem down to this commit. Prior to that, it did not crash.

git checkout 3e6f1a6212c2b8d66c4146c8462879ded8728da6
python3.12 -m pip install .

Then run mypy:

$ mypy apps/app-name/
<snip>
Found 10 errors in 4 files (checked 62 source files)

System information

  • OS:
  • python version: 3.12
  • django version: 5.1.4
  • mypy version: 1.13
  • django-stubs version: 5.1.0 and higher
  • django-stubs-ext version: 5.1.0 and higher

thinkwelltwd avatar Dec 09 '24 19:12 thinkwelltwd

Is there any fix to this? If I downgrade django-stubs version all of a sudden I get 51 errors, such as django-stubs\db\models\constraints.pyi:43: note: "CheckConstraint" defined here. But if I try to upgrade I get the same error as you.

TreyWW avatar Dec 28 '24 14:12 TreyWW

Having the same issue with latest:

mypy = "==1.17.0"
django-stubs = "==5.2.2"
django-stubs-ext = "==5.2.2"
(py3.12) ➜  mypy --show-traceback
/Users/muser/project/.venv/lib/python3.12/site-packages/django-stubs/http/request.pyi:56: 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: 1.17.0
Traceback (most recent call last):
  File "mypy/semanal.py", line 7293, in accept
  File "mypy/nodes.py", line 1406, in accept
  File "mypy/semanal.py", line 3233, in visit_assignment_stmt
  File "mypy/semanal.py", line 3767, in process_type_annotation
  File "mypy/semanal.py", line 6939, in defer
AssertionError: Must not defer during final iteration
/Users/muser/project/.venv/lib/python3.12/site-packages/django-stubs/http/request.pyi:56: : note: use --pdb to drop into pdb

Is there any workaround?

matejsp avatar Jul 21 '25 09:07 matejsp

+1 same traceback with custom user model and mypy==1.17.0 / django-stubs==5.2.2

geoffrey-eisenbarth avatar Jul 26 '25 02:07 geoffrey-eisenbarth

same: django 5.2.7

mypy==1.18.2
django-cte==2.0.0
django-cte-stubs==1.1.0
django-stubs==5.2.7
django-stubs-ext==5.2.7

evgenyslab avatar Oct 14 '25 15:10 evgenyslab