Skip to content

Fix ConnectionFactory.build_url() for SQLite (issue #7)#191

Merged
tmgbedu merged 1 commit into
mainfrom
task/fix-sqlite-build-url-1218
Jul 23, 2026
Merged

Fix ConnectionFactory.build_url() for SQLite (issue #7)#191
tmgbedu merged 1 commit into
mainfrom
task/fix-sqlite-build-url-1218

Conversation

@tmgbedu

@tmgbedu tmgbedu commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • ConnectionFactory.build_url() formatted every driver with the same {scheme}://{user}:{pwd}@{host}:{port}/{db} template. For SQLite, port is an empty string, producing sqlite+aiosqlite://:@localhost:/database.sqlite, which crashes SQLAlchemy's URL._assert_port() with ValueError: invalid literal for int() with base 10: ''.
  • SQLite connections have no host/user/password/port, so build_url() now special-cases driver == "sqlite" and returns f"{scheme}:///{db}" — this naturally produces sqlite+aiosqlite:///relative.db for relative paths and sqlite+aiosqlite:////abs/path.db for absolute paths (the leading / in the path supplies the fourth slash).
  • postgres/mysql URL building is untouched.

Fixes #7.

Test plan

  • Added regression tests to fastapi_startkit/tests/masoniteorm/config/test_db_url.py covering relative database path, absolute database path, and that host/user/password/port keys are ignored for sqlite
  • uv run pytest fastapi_startkit/tests/masoniteorm/config/test_db_url.py -v — 7 passed
  • uv run pytest --ignore=tests/masoniteorm/postgres -q (run from fastapi_startkit/) — 1836 passed, 7 skipped
  • uv run ruff check / uv run ruff format --check on changed files — clean

SQLite was going through the same {scheme}://{user}:{pwd}@{host}:{port}/{db}
template as postgres/mysql, producing an empty port segment
(sqlite+aiosqlite://:@localhost:/database.sqlite) that crashes
SQLAlchemy's URL._assert_port(). SQLite connections have no
host/user/password/port, so build the URL as {scheme}:///{db} instead,
which also correctly yields a four-slash URL for absolute paths.
@tmgbedu
tmgbedu merged commit 59a9c64 into main Jul 23, 2026
5 checks passed
@tmgbedu
tmgbedu deleted the task/fix-sqlite-build-url-1218 branch July 23, 2026 21:28
@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