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

django.contrib.auth should return the configured User type #2293

Closed
asottile-sentry opened this issue Jul 30, 2024 · 1 comment · Fixed by #2335
Closed

django.contrib.auth should return the configured User type #2293

asottile-sentry opened this issue Jul 30, 2024 · 1 comment · Fixed by #2335
Labels
bug Something isn't working

Comments

@asottile-sentry
Copy link

Bug report

def authenticate(request: HttpRequest | None = ..., **credentials: Any) -> AbstractBaseUser | None: ...

probably would require a mypy plugin to adjust the type similar to the one for django.contrib.auth.get_user_model

I suspect #1353 is related at least and may be solved by fixing this as well

(sorry for cutting off the rest of the bug report template -- I haven't been able to pin down a minimal example!)

@asottile-sentry asottile-sentry added the bug Something isn't working label Jul 30, 2024
@flaeppe
Copy link
Member

flaeppe commented Jul 31, 2024

After reading through #1353 it seems that will also be closed by adjusting authenticate with the plugin.

I think one form of minimal example is

# myapp/models.py
from django.db import models

class User(models.Model): ...
# settings.py
INSTALLED_APPS = ["django.contrib.contenttypes", "django.contrib.auth", "myapp"]
AUTH_USER_MODEL = "myapp.User"
# main
from django.contrib.auth import authenticate
reveal_type(authenticate())  # N: Revealed type is "Union[myapp.models.User, None]"

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

Successfully merging a pull request may close this issue.

2 participants