Skip to content

fix(litestar): raise KeyError for unknown config lookups - #732

Merged
cofin merged 5 commits into
mainfrom
fix/litestar-config-lookup-key-diagnostics
Sep 7, 2026
Merged

fix(litestar): raise KeyError for unknown config lookups#732
cofin merged 5 commits into
mainfrom
fix/litestar-config-lookup-key-diagnostics

Conversation

@cofin

@cofin cofin commented Sep 7, 2026

Copy link
Copy Markdown
Member

Description

Fixes config lookup diagnostics in SQLSpecPlugin.get_config():

  • When querying an identifier that does not match any registered configuration identity or dependency key, SQLSpecPlugin.get_config() now immediately raises a KeyError detailing all available bind_keys and dependency keys.
  • Previously, unregistered plugins threw ImproperConfigurationError prematurely for unknown names or unmatched config types. ImproperConfigurationError is now reserved strictly for valid dependency keys accessed prior to application registration.
  • Added comprehensive unit tests covering unknown string keys, unmatched config types, and foreign config instances before/after registration.
  • Updated documentation and changelog.

Verification

  • Unit tests: pytest tests/unit/extensions/test_litestar passed (108 passed).
  • Linting & Formatting: ruff check and ruff format passed.

cofin added 2 commits August 24, 2026 23:25
SQLSpecPlugin.get_config() raised ImproperConfigurationError about
application registration for any identifier that matched no configuration,
because _dependency_state applied the registration guard before checking
whether its input was a dependency key at all.

Unknown names, unmatched config types, and configs belonging to another
registry now raise KeyError listing the available bind keys and dependency
keys. That matches the documented contract and the behavior already in
place after registration.

Generated Litestar dependency keys remain registration-bound.
State in the dependency-injection guide that an identifier matching neither
a registry identity nor a dependency key raises KeyError listing every
available bind key and dependency key, in both lifecycle phases, and record
the fix in the changelog.
@codecov-commenter

codecov-commenter commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.10%. Comparing base (4f7afc5) to head (ce49c19).

Files with missing lines Patch % Lines
sqlspec/builder/_ddl.py 50.00% 2 Missing ⚠️
sqlspec/extensions/litestar/plugin.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #732      +/-   ##
==========================================
+ Coverage   77.08%   77.10%   +0.02%     
==========================================
  Files         487      487              
  Lines       69819    69822       +3     
  Branches     9676     9677       +1     
==========================================
+ Hits        53819    53837      +18     
+ Misses      12541    12528      -13     
+ Partials     3459     3457       -2     
Flag Coverage Δ
integration 60.60% <0.00%> (-0.01%) ⬇️
py3.10 75.38% <70.00%> (+0.01%) ⬆️
py3.11 75.39% <70.00%> (+0.02%) ⬆️
py3.12 75.38% <70.00%> (+0.01%) ⬆️
py3.13 75.39% <70.00%> (+0.01%) ⬆️
py3.14 76.30% <70.00%> (+0.01%) ⬆️
unit 65.16% <70.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sqlspec/extensions/litestar/plugin.py 81.03% <83.33%> (+0.38%) ⬆️
sqlspec/builder/_ddl.py 66.98% <50.00%> (+1.45%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cofin
cofin merged commit 0d8d4a5 into main Sep 7, 2026
40 of 42 checks passed
@cofin
cofin deleted the fix/litestar-config-lookup-key-diagnostics branch September 7, 2026 21:34
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.

2 participants