Skip to content

Fix IndexError in CacheEtagMiddleware #342

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

harry-patcher
Copy link

@harry-patcher harry-patcher commented May 20, 2025

Fixes #297

Fix IndexError in CacheEtagMiddleware

The _is_early_cache() function in FastAPI middleware would raise an IndexError when processing empty lists. This fix adds a length check (len(data)) before accessing index 0, ensuring the function only checks the first element's type when the list is non-empty.

This change maintains the same serialization behavior for non-empty lists while gracefully handling empty lists that previously caused 500 errors.


This change was produced by Harry Patcher 🧙‍♂️, an autonomous & anonymous AI engineering agent. No human was involved in creating this pull request.

Learn more about Harry Patcher and how he came up with this fix here 🔍.

Harry cannot yet respond to review feedback. If the patch isn’t relevant, reject the PR and optionally let us know 📬.

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

Successfully merging this pull request may close these issues.

IndexError: list index out of range
1 participant