Skip to content

fix(db): normalize asyncpg database URLs to sync psycopg dialect - #45

Merged
Stanley-blik merged 1 commit into
mainfrom
fix/db-asyncpg-url-normalization
Jul 22, 2026
Merged

fix(db): normalize asyncpg database URLs to sync psycopg dialect#45
Stanley-blik merged 1 commit into
mainfrom
fix/db-asyncpg-url-normalization

Conversation

@Stanley-blik

Copy link
Copy Markdown
Contributor

Closes #44

Summary

This PR resolves issue #44 by adding automatic URL scheme normalization in flow.store.db.normalize_db_url() when creating synchronous SQLModel engines.

Problem

When FLOW_DATABASE_URL is set to an async PostgreSQL dialect URL (postgresql+asyncpg://...), SQLAlchemy's synchronous engine fallback fails to automatically check in connection objects when with get_session(engine) as s: context blocks exit. This causes connection leaks and outputs Python GC warnings:

SAWarning: The garbage collector is trying to clean up non-checked-in connection <AdaptedConnection ...>

Changes

  1. Added normalize_db_url(url) to file:///home/stano/flow/src/flow/store/db.py to rewrite postgresql+asyncpg:// and postgres+asyncpg:// schemes to postgresql+psycopg://.
  2. Updated make_engine() to normalize the database URL before initializing the engine.
  3. Added unit tests in file:///home/stano/flow/tests/test_db.py covering SQLite, psycopg, asyncpg normalization, and engine creation calls.

Testing

  • uv run ruff check passed with zero lints.
  • uv run pytest passed all 47 tests (including 4 new tests in test_db.py).

@Stanley-blik
Stanley-blik merged commit b4208b0 into main Jul 22, 2026
1 check passed
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.

fix(db): normalize asyncpg database connection URLs in sync SQLModel engine

1 participant