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

Broken when Custom groups in AbstractBaseUser #783

Open
VaZark opened this issue Aug 12, 2022 · 2 comments
Open

Broken when Custom groups in AbstractBaseUser #783

VaZark opened this issue Aug 12, 2022 · 2 comments

Comments

@VaZark
Copy link

VaZark commented Aug 12, 2022

Setup

The django project uses an AbstractBaseUser along with a Custom group for permissions.

class CustomGroup(Group):
    additional_field = models.CharField(max_length=10)
    ....

class CustomUser(AbstractBaseUser, PermissionsMixin):
    groups = models.ManyToManyField(CustomGroup)
    ....

Error / Unexpected Behaviour

When opening he django admin, we get the error Cannot query "AnonymousUser": Must be "Group" instance.

A little bit of googling gives me the impression that .has_perm() function invokes the Group class directly and does not update itself to reflect the custom group classes defined in the user model

Ideal Solution

Django guardian should detect the Group model associated with the user model and use it for perms. Or mention a workaround in the docs

@VaZark VaZark changed the title Broken when Custom groups in AbstractBaseuse!r Broken when Custom groups in AbstractBaseUser Aug 12, 2022
@VaZark
Copy link
Author

VaZark commented Aug 12, 2022

The initial migration runs a foreign key to the Group model under auth automatically.

('group', models.ForeignKey(to='auth.Group', on_delete=models.CASCADE)), in 0001_initial.py

Can the string made into a swappable dependency or set by using a custom variable in settings ??

@michael-k
Copy link
Collaborator

See #504

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

No branches or pull requests

2 participants