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

IndexError: list index out of range #297

Open
leestorm4520 opened this issue Oct 30, 2024 · 0 comments
Open

IndexError: list index out of range #297

leestorm4520 opened this issue Oct 30, 2024 · 0 comments

Comments

@leestorm4520
Copy link

I am using cashews in my fastapi application and whenever the endpoint returns an empty list, CacheEtagMiddleware wont be able to serialize it, resulting in IndexError: list index out of range.
_is_early_cache() should be  "return isinstance(data, list) and len(data) and isinstance(data[0], datetime) "

def _get_etag(cached_data: Any) -> str:
if _is_early_cache(cached_data):
cached_data = cached_data[1]
if not isinstance(cached_data, bytes):
cached_data = cached_data.body if isinstance(cached_data, Response) else DEFAULT_PICKLER.dumps(cached_data)
return blake2s(cached_data).hexdigest()

def _is_early_cache(data: Any) -> bool:
return isinstance(data, list) and isinstance(data[0], datetime)

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

1 participant