-
Notifications
You must be signed in to change notification settings - Fork 103
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
Default has_object_permission implementation in BaseHasAPIKey is redundant #150
Comments
Absolutely, sounds like a no brainer. I think a separate PR for this particular type hint tweak would be acceptable? As for |
Ah, I did try to look why Any way it is handled, it's a shame that there's no good way to cache the result of |
Looks like there's already an issue for this against DRF encode/django-rest-framework#7117 . It looks like there's a PR to fix it exactly as I would have suggested (in the OR class) which didn't make it into the recent 3.12 release, but hopefully should make it into the next one. So I'd say, yes, djangorestframework-api-key should remove this workaround and anyone who needs it prior to the upstream DRF fix should do it themselves. And yes, a separate PR for fixing the type annotation would be a simple fix, but it is moot if the method gets removed. |
@sparkyb As I come back to this repo to move a few things forward, I noticed I had incorrectly assumed this was only an external DRF issue. There is a problem with how DRF handles bitwise permission operations, but we still make an inappropriate use of I agree we should drop We basically need to undo #25*, and maybe add a note about encode/django-rest-framework#7117 in the docs that mention bitwise operations. (* That "fix" is 3 years old. I'm thinking -- all this time, computers running |
The PR encode/django-rest-framework#7117 was merged on the DRF side. Now, bitwise OR checks for both This does confirm that we can revert #25 and have folks rely on the new fix from the DRF. |
djangorestframework-api-key/src/rest_framework_api_key/permissions.py
Lines 53 to 56 in 2a343ee
Right now the permission
BaseHasAPIKey
implementhas_object_permission
and just callshas_permission
. This is an incorrect implementation ofBasePermission
.has_object_permission
is only called afterhas_permission
has already passed, so this implementation is redundant (and inefficient since it will cause a redundant database lookup for the API key).Also, the type of
obj
is annotated asAbstractAPIKey
, but the object passed tohas_object_permission
would be an instance of whatever model the view is acting on where this permission is used, not the API key.The text was updated successfully, but these errors were encountered: