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

Check in get_objects_for_user does not respect GUARDIAN_GET_CONTENT_TYPE #727

Open
markedwards opened this issue Dec 16, 2020 · 2 comments · May be fixed by #728
Open

Check in get_objects_for_user does not respect GUARDIAN_GET_CONTENT_TYPE #727

markedwards opened this issue Dec 16, 2020 · 2 comments · May be fixed by #728

Comments

@markedwards
Copy link

There is an equality check in https://github.com/django-guardian/django-guardian/blob/devel/guardian/shortcuts.py#L533 which fails when GUARDIAN_GET_CONTENT_TYPE is set.

The check in question is:

if ctype.model_class() != queryset.model

This works in a standard case, however if GUARDIAN_GET_CONTENT_TYPE is used and the expected content type for the model is not the content type for the model itself, this will fail. My suggestion is to replace this check with:

if ctype != get_content_type(queryset.model):

I'm happy to create a PR for this, but wanted to pose it for feedback first.

@markedwards
Copy link
Author

PR created. I've tested pretty thoroughly in my app and it works well. Let me know if there are any concerns or questions.

@danielshorten
Copy link

Hi! Would love to get this change merged into an official release! Currently working off a fork of django-guardian with the changes in #728.

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