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

get_perms returns empty list while get_user_perms returns permissions #786

Open
BSVogler opened this issue Aug 31, 2022 · 2 comments
Open

Comments

@BSVogler
Copy link

I wrote a script to give me all objects which don't have enough permissions.
I used shortcuts get_perms to check the permissions for the user and I found some entries because they returned []. But on closer inspection, I can see the obejcts have permissions and they are returned when I use get_user_perms.

Shouldn't get_perms return a superset of get_user_perms?

Here is my script, using guardian 2.4.0

from guardian.shortcuts import get_user_perms, get_perms
from app.models import PreferencesRecord

for pref in tqdm.tqdm(PreferencesRecord.objects.all()):
    perms = get_perms(pref.user, pref)
    if len(perms) < 4:
        print(f"User {pref.user.username} ({pref.user.id}) has {len(perms)} permissions on {pref.id}")
        user_perms = get_user_perms(pref.user, pref)
        if user_perms != perms:
            print(f"But the user permissions return {user_perms}, while perms are {perms}")
@kmmbvnr
Copy link

kmmbvnr commented May 6, 2024

Have you have GUARDIAN_AUTO_PREFETCH set to True in your Django settings?

@BSVogler
Copy link
Author

BSVogler commented May 6, 2024

Unless I made a mistake I don't think that it was overwritten to be True.

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