Skip to content

fix(datastructures): MutableScopeHeaders.getall() treats an empty-list default as "no default" - #4924

Open
chuenchen309 wants to merge 1 commit into
litestar-org:mainfrom
chuenchen309:fix/mutable-scope-headers-getall-empty-default
Open

fix(datastructures): MutableScopeHeaders.getall() treats an empty-list default as "no default"#4924
chuenchen309 wants to merge 1 commit into
litestar-org:mainfrom
chuenchen309:fix/mutable-scope-headers-getall-empty-default

Conversation

@chuenchen309

@chuenchen309 chuenchen309 commented Jul 14, 2026

Copy link
Copy Markdown

What

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 I verified this

  • Added test_mutable_scope_headers_getall_not_found_empty_list_default, confirmed it fails with KeyError before the fix and passes after.
  • Ran the full tests/unit/test_datastructures/ suite: 148 passed.
  • mypy and pre-commit (ruff, unasyncd, typos) clean.

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

…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>
@chuenchen309
chuenchen309 requested review from a team as code owners July 14, 2026 11:31
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.29%. Comparing base (bd18fd4) to head (a9bad2b).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant