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

About second to permission check #252

Closed
skybrd opened this issue Sep 18, 2023 · 1 comment
Closed

About second to permission check #252

skybrd opened this issue Sep 18, 2023 · 1 comment
Labels
duplicate A similar issue or PR already exists

Comments

@skybrd
Copy link

skybrd commented Sep 18, 2023

Describe the bug
API request with enabled auth permission_classes = [HasAPIKey] process about a second, without - 14 ms

To Reproduce
Steps to reproduce the behavior:

  1. pip install "djangorestframework-api-key==2.3.0"
  2. Configure (as in the documentation)
  3. Add permission_classes = [HasAPIKey] to ViewSet class API handler
  4. See result

Expected behavior
Expected to work without significant delays.

Desktop (please complete the following information):

  • OS: MacOS
  • Version: 10.13.6
  • Python Version: 3.11.5
  • Django Version: 4.2.4
  • DRF Version: 3.14.0

How did I fix it
As a quick solution, I removed the recursive call in models.py, class BaseAPIKeyManager - method get_from_key call is_valid and vice versa. Perhaps it was a mistake - now all works correct, the request is processed in 14 ms

    def get_from_key(self, key: str) -> "AbstractAPIKey":
        prefix, _, _ = key.partition(".")
        queryset = self.get_usable_keys()

        try:
            api_key = queryset.get(prefix=prefix)
        except self.model.DoesNotExist:
            raise  # For the sake of being explicit.

        # if not api_key.is_valid(key):
        #     raise self.model.DoesNotExist("Key is not valid.")
        # else:
        return api_key
@florimondmanca
Copy link
Owner

@skybrd Hi

If I’m correct, this relates to #173 which as been dealt with, the fix should be released soon — see #248.

I am closing this for now but if you think this will not be fixed by the pending fix, we can discuss further.

thanks!

@florimondmanca florimondmanca added the duplicate A similar issue or PR already exists label Sep 18, 2023
@florimondmanca florimondmanca closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2023
@skybrd skybrd changed the title About second on permission check About second to permission check Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate A similar issue or PR already exists
Projects
None yet
Development

No branches or pull requests

2 participants