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

fix: UserAdmin accepts AbstractUser #1783

Closed
wants to merge 2 commits into from

Conversation

GabDug
Copy link
Contributor

@GabDug GabDug commented Oct 19, 2023

I have made things!

Fix an issue I introduced with UserAdmin: if you inherit from it with a custom User it would not work, only with Django base User.

If needed, can add a test case akin of:

@admin.register(CustomUser)
class CustomUserAdmin(UserAdmin[CustomUser]):
   ...

and

@admin.register(CustomUser)
class CustomUserAdmin(UserAdmin):
   ...

Any feedback is appreciated!

Related issues


class GroupAdmin(admin.ModelAdmin[Group]): ...

class UserAdmin(admin.ModelAdmin[User]):
class UserAdmin(admin.ModelAdmin[_M], Generic[_M]):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class UserAdmin(admin.ModelAdmin[_M], Generic[_M]):
class UserAdmin(admin.ModelAdmin[_M]):

I do not think the Generic is needed.

from django.http.request import HttpRequest
from django.http.response import HttpResponse

csrf_protect_m: Any
sensitive_post_parameters_m: Any
_M = TypeVar("_M", bound=AbstractUser, covariant=False)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_M = TypeVar("_M", bound=AbstractUser, covariant=False)
_M = TypeVar("_M", bound=AbstractUser)

covariant is False by default I think.

@@ -1,16 +1,17 @@
from typing import Any
from typing import Any, Generic, TypeVar

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from typing import Any, Generic, TypeVar
from typing import Any, TypeVar

As per below comments, I do not think this is needed.

@vadimshvetsov
Copy link
Contributor

vadimshvetsov commented May 8, 2024

Hey @GabDug, thanks for your PR. Do you plan to address comments or I can do it for you and open new PR? I need this also.

@kolanos
Copy link

kolanos commented Feb 1, 2025

Shouldn't this be checking for inheritance from AbstractBaseUser and not AbstractUser? A lot of people create a custom user model based on AbstractBaseUser, such as not including a username field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants