-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
has_permission gets called twice #8987
Comments
Hello there! First of all, it will run the To optimize performance, consider caching your query based on the request and using it repeatedly instead of running a query on the database each time. Furthermore, please provide us with the details of your custom permission classes here. |
Yes. In my case, I can use cache to prevent extra DB hit (actually I already have it). My point is, assume a I'm not trying to solve it in my project, as the solution for me simply can be a cache. I'm just looking for enhancement and having a better optimization. |
I think you might have misunderstood the class "OR." class OperationHolderMixin:
def __and__(self, other):
return OperandHolder(AND, self, other)
def __or__(self, other):
return OperandHolder(OR, self, other)
def __rand__(self, other):
return OperandHolder(AND, other, self)
def __ror__(self, other):
return OperandHolder(OR, other, self)
def __invert__(self):
return SingleOperandHolder(NOT, self) The In the composed_permissions = IsAuthenticatedUserOwner | permissions.IsAdminUser
has_perm = composed_permissions().has_object_permission(request, None, None) It will execute This is the edited version: I understand what is happening here. |
Thanks for your suggestion. But I was more looking for a solution to fix it in DRF, not in my code. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hi!
In drf==3.14, the has_object_permission code has changed in
OR
class in 4aea8dd.The problem is, we are calling has_permission twice here, and I have some queries in my custom permission class, in has_permission method. So for each request, my queries are running twice and it makes my API slow.
I'd love to fix it myself, but I couldn't achieve any good solution for preventing calling has_permission again.
Any idea ?
The text was updated successfully, but these errors were encountered: