Skip to content
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

False positive "BaseManager[User]" has no attribute "create_user" on default User Model #1654

Closed
johnthagen opened this issue Aug 14, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@johnthagen
Copy link

Bug report

What's wrong

The following code:

from django.contrib.auth.models import User

user = User.objects.create_user(username="user")

Generates an type checking error:

main.py:3: error: "BaseManager[User]" has no attribute "create_user"  [attr-defined]

This works at runtime, however.

The Django User derives from AbstractUser, which sets:

objects = UserManager()

And UserManager defines:

def create_user(self, username, email=None, password=None, **extra_fields):
    ...

How is that should be

Expect no type error.

System information

  • OS: macOS
  • python version: 3.10.11
  • django version: 4.2.4
  • mypy version: 1.5.0
  • django-stubs version: 4.2.3
  • django-stubs-ext version: 4.2.2

This error did not appear in Mypy 1.4.1, but started appearing in 1.5.0.

@johnthagen johnthagen added the bug Something isn't working label Aug 14, 2023
@intgr
Copy link
Collaborator

intgr commented Aug 14, 2023

This is a symptom of issue #1648, closing as duplicate. Unfortunately fixing it is not straightforward.

As a work-around you can downgrade mypy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants