fix(datastructures): MutableScopeHeaders.getall() treats an empty-list default as "no default" - #4924
Open
chuenchen309 wants to merge 1 commit into
Conversation
…t default as "no default" `getall(key, default)` used `if default:` to decide whether a default was supplied, so an explicit `default=[]` (a legitimate way to ask for "return an empty list if the header is missing" rather than raising) is falsy and gets treated the same as `default=None` — raising KeyError instead of returning `[]`. Fix: check `if default is not None:` instead, matching the type signature (`default: list[str] | None = None`) and the pattern already used elsewhere in this file (e.g. `MutableScopeHeaders.__getitem__`). How verified: added test_mutable_scope_headers_getall_not_found_empty_list_default, confirmed it fails with KeyError before the fix and passes after. Full test_datastructures/ suite (148 tests) passes. mypy and pre-commit (ruff, unasyncd, typos) clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4924 +/- ##
=======================================
Coverage 67.29% 67.29%
=======================================
Files 293 293
Lines 15228 15228
Branches 1728 1728
=======================================
Hits 10248 10248
Misses 4833 4833
Partials 147 147 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
getall(key, default)usedif default:to decide whether a default was supplied, so an explicitdefault=[](a legitimate way to ask for "return an empty list if the header is missing" rather than raising) is falsy and gets treated the same asdefault=None— raisingKeyErrorinstead of returning[].Fix
Check
if default is not None:instead, matching the type signature (default: list[str] | None = None) and the pattern already used elsewhere in this file (e.g.MutableScopeHeaders.__getitem__).How I verified this
test_mutable_scope_headers_getall_not_found_empty_list_default, confirmed it fails withKeyErrorbefore the fix and passes after.tests/unit/test_datastructures/suite: 148 passed.Disclosure
I used AI assistance (Claude) to help investigate and draft this fix, but I personally reviewed the root cause, wrote/ran the regression test, and reviewed the final diff before submitting.
📚 Documentation preview 📚: https://litestar-org.github.io/litestar-docs-preview/4924