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

ignore_exc should return default values #350

Closed
Justylol opened this issue Sep 21, 2021 · 1 comment
Closed

ignore_exc should return default values #350

Justylol opened this issue Sep 21, 2021 · 1 comment

Comments

@Justylol
Copy link

Justylol commented Sep 21, 2021

Its better for ignore_exc to use default value on return, instead of None. It will be real missing cache behaviour and will help with errors when default expected. For example:

Django==3.2
djangorestframework==3.11.1
pymemcache==3.5.0

rest_framework.throttling module

        self.history = self.cache.get(self.key, [])
        self.now = self.timer()

        # Drop any requests from the history which have now passed the
        # throttle duration
        while self.history and self.history[-1] <= self.now - self.duration:
            self.history.pop()
        if len(self.history) >= self.num_requests:
            return self.throttle_failure()

This code with in Django with PyMemcacheCache cache backend and ignore_exc option leads to an error object of type 'NoneType' has no len() because instead of returning list as missing cache result, it returns None.

jogo added a commit to jogo/pymemcache that referenced this issue Sep 22, 2021
ignore_exc should treat an error as a cache miss and default specifies
what should be returned on a miss.

Fixes issue pinterest#350
@jogo
Copy link
Contributor

jogo commented Sep 22, 2021

Thank you for the bug report, #351 should address this

Pankrat added a commit to Pankrat/pymemcache that referenced this issue Oct 4, 2021
When using `HashClient` with `ignore_exc`, `get` would always return
`None` if no server is available. The other clients return the default
value in this case.

Return the default value so `HashClient` behaves like the other
clients.

Fixes a variation of issue pinterest#350
Pankrat pushed a commit to Pankrat/pymemcache that referenced this issue Oct 5, 2021
ignore_exc should treat an error as a cache miss and default specifies
what should be returned on a miss.

Fixes issue pinterest#350
Pankrat added a commit to Pankrat/pymemcache that referenced this issue Oct 7, 2021
When using `HashClient` with `ignore_exc`, `get` would always return
`None` if no server is available and the default is passed as a
positional argument. The other clients return the default
value in this case. An earlier fix only had the desired effect when
passing `default` as a keyword argument.

Return the default value so `HashClient` behaves like the other
clients even when using

Fixes another variation of issue pinterest#350
Pankrat added a commit to Pankrat/pymemcache that referenced this issue Oct 7, 2021
When using `HashClient` with `ignore_exc`, `get` would always return
`None` if no server is available and the default is passed as a
positional argument. The other clients return the default
value in this case. An earlier fix only had the desired effect when
passing `default` as a keyword argument.

Return the default value so `HashClient` behaves like the other
clients even when using

Fixes another variation of issue pinterest#350
Pankrat added a commit to Pankrat/pymemcache that referenced this issue Oct 14, 2021
When using `HashClient` with `ignore_exc`, `get` would always return
`None` if no server is available and the default is passed as a
positional argument. The other clients return the default
value in this case. An earlier fix only had the desired effect when
passing `default` as a keyword argument.

Return the default value so `HashClient` behaves like the other
clients even when using

Fixes another variation of issue pinterest#350
jparise pushed a commit that referenced this issue Feb 20, 2022
ignore_exc should treat an error as a cache miss and default specifies
what should be returned on a miss.

Fixes issue #350
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