test(database): regression test for DatabaseManager connection lookup (GH #6)#192
Merged
Conversation
… (GH #6) GH issue #6 reported DatabaseManager.connection() indexing self.config[name] directly, causing a KeyError when DatabaseProvider.register() binds the full resolved config (default/connections/migrations) rather than a flat {connection_name: {...}} dict. That lookup was already corrected to go through the nested 'connections' key (commit 6eae52b) and raises a clean ValueError on a missing connection, so this is not reproducible on current main -- verified by reverting the lookup locally, which reproduces the exact reported KeyError: 'sqlite'. Adds a regression test covering: connection resolution through the nested connections dict, default-name resolution from the top-level 'default' key, the ValueError (not KeyError) on a missing connection, and end-to-end DatabaseProvider wiring, so any future regression on this path fails loudly.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
GitHub issue #6 reports
DatabaseManager.connection()indexingself.config[name]directly, which crashes withKeyError: 'sqlite'becauseDatabaseProvider.register()passes the full resolved config (default/connections/migrations) rather than a flat{connection_name: {...}}dict.Investigation finding: this is already fixed on
main.DatabaseManager.connection()currently resolves viaself.config.get("connections", {}).get(name)and raises a cleanValueErrorwhen the connection is missing — that fix landed in commit6eae52bf("database improvements"), which predates the currentmainHEAD. I confirmed the bug does not reproduce today:python artisan db:migrateruns cleanly against a fresh app (noKeyError).self.config[name]) does throwKeyError: 'sqlite'exactly as reported — reverting the fix locally reproduces the issue immediately, confirming both that the bug was real and that it's now resolved.Since there was no live bug to fix in the source, this PR adds a regression test locking in the correct behavior so this can't silently regress:
connectionsdict.defaultkey.ValueError(notKeyError).DatabaseProviderwiring produces aDatabaseManagerwhoseconnection()resolves cleanly.Test plan
uv run pytest fastapi_startkit/tests/masoniteorm/config/test_manager.py -v— 4 passeduv run pytest fastapi_startkit/src/fastapi_startkit/tests/ -v(ran via--ignore=tests/masoniteorm/postgresfromfastapi_startkit/) — 1837 passed, 7 skipped, no regressionspython artisan db:migrateagainst a real sqlite fixture app — migrates cleanly, noKeyErrorKeyError: 'sqlite'from the issue, then restored the fix