fix(litestar): raise KeyError for unknown config lookups - #732
Merged
Conversation
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 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.
Description
Fixes config lookup diagnostics in
SQLSpecPlugin.get_config():SQLSpecPlugin.get_config()now immediately raises aKeyErrordetailing all availablebind_keys and dependency keys.ImproperConfigurationErrorprematurely for unknown names or unmatched config types.ImproperConfigurationErroris now reserved strictly for valid dependency keys accessed prior to application registration.Verification
pytest tests/unit/extensions/test_litestarpassed (108 passed).ruff checkandruff formatpassed.