Skip to content

fix: replace asyncpg with psycopg2 in PostgreSQLRepository (#35)#36

Merged
luiscarbonel1991 merged 3 commits into
mainfrom
fix/asyncpg-event-loop
Mar 24, 2026
Merged

fix: replace asyncpg with psycopg2 in PostgreSQLRepository (#35)#36
luiscarbonel1991 merged 3 commits into
mainfrom
fix/asyncpg-event-loop

Conversation

@luiscarbonel1991

Copy link
Copy Markdown
Owner

Summary

  • Replace create_async_engine + asyncpg with psycopg2 + asyncio.to_thread()
  • Mirrors the proven RedshiftRepository pattern (connection-per-query, no event loop binding)
  • Remove asyncpg dependency from pyproject.toml
  • Bump version to 0.2.0rc10

What changed

Aspect Before (asyncpg) After (psycopg2)
Driver create_async_engine + asyncpg psycopg2.connect() + asyncio.to_thread()
Connection model Shared pool bound to one event loop Fresh connection per query
Param style :named via SQLAlchemy text() %s / %(name)s via psycopg2
Sync context support Broken Works

Test plan

  • 195 non-integration tests pass
  • Integration tests against Docker PostgreSQL
  • Manual test from sync context (Strands @tool inside FastAPI)

Closes #35

Migrates PostgreSQLRepository to psycopg2 (sync) + asyncio.to_thread().
Bump version to 0.2.0rc10. Closes #35
@luiscarbonel1991 luiscarbonel1991 added the bug Something isn't working label Mar 24, 2026
…35)

postgres:// is a supported alias throughout the codebase (RepositoryFactory,
cli.py, mcp_server) but _parse_connection_string only stripped postgresql://.
Without stripping, split(":", 1) yields user="postgres" password="//user:pass"
causing silent authentication failures.
Replace naive rsplit/split parsing with urllib.parse.urlparse to handle:
- Query parameters (e.g., ?sslmode=require) leaked into database name
- URL-encoded characters in passwords (e.g., %40 for @) not decoded
- Both postgresql:// and postgres:// schemes
@luiscarbonel1991 luiscarbonel1991 merged commit 49bed58 into main Mar 24, 2026
1 check passed
@luiscarbonel1991 luiscarbonel1991 deleted the fix/asyncpg-event-loop branch March 24, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: PostgreSQLRepository uses asyncpg which breaks when called from sync contexts (event loop mismatch)

1 participant