Skip to content

test(database): regression test for DatabaseManager connection lookup (GH #6)#192

Merged
tmgbedu merged 1 commit into
mainfrom
task/db-manager-config-fix-1219
Jul 23, 2026
Merged

test(database): regression test for DatabaseManager connection lookup (GH #6)#192
tmgbedu merged 1 commit into
mainfrom
task/db-manager-config-fix-1219

Conversation

@tmgbedu

@tmgbedu tmgbedu commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

GitHub issue #6 reports DatabaseManager.connection() indexing self.config[name] directly, which crashes with KeyError: 'sqlite' because DatabaseProvider.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 via self.config.get("connections", {}).get(name) and raises a clean ValueError when the connection is missing — that fix landed in commit 6eae52bf ("database improvements"), which predates the current main HEAD. I confirmed the bug does not reproduce today:

  • python artisan db:migrate runs cleanly against a fresh app (no KeyError).
  • Direct reproduction with the old flat-indexing code (self.config[name]) does throw KeyError: '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:

  • Connection resolves through the nested connections dict.
  • Default connection name resolves from the top-level default key.
  • A missing connection raises ValueError (not KeyError).
  • End-to-end: DatabaseProvider wiring produces a DatabaseManager whose connection() resolves cleanly.

Test plan

  • uv run pytest fastapi_startkit/tests/masoniteorm/config/test_manager.py -v — 4 passed
  • uv run pytest fastapi_startkit/src/fastapi_startkit/tests/ -v (ran via --ignore=tests/masoniteorm/postgres from fastapi_startkit/) — 1837 passed, 7 skipped, no regressions
  • python artisan db:migrate against a real sqlite fixture app — migrates cleanly, no KeyError
  • Sanity check: reverted the nested-lookup fix locally and confirmed the new test reproduces the exact KeyError: 'sqlite' from the issue, then restored the fix

… (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.
@tmgbedu
tmgbedu merged commit a3a12f9 into main Jul 23, 2026
5 checks passed
@tmgbedu
tmgbedu deleted the task/db-manager-config-fix-1219 branch July 23, 2026 21:30
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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