Fix: asyncpg needs postgresql:// not postgresql+asyncpg://
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 49s
CI / test-go-edu-search (push) Successful in 1m1s
CI / test-python-klausur (push) Failing after 2m43s
CI / test-python-agent-core (push) Successful in 42s
CI / test-nodejs-website (push) Has been cancelled

Strip SQLAlchemy dialect prefix from DATABASE_URL for asyncpg.
Set search_path via server_settings on pool creation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-04-24 13:45:26 +02:00
parent 7ff9860c69
commit c0b723e3b5

View File

@@ -15,10 +15,15 @@ from typing import Any, Dict, List, Optional
logger = logging.getLogger(__name__)
DATABASE_URL = os.getenv(
_RAW_DB_URL = os.getenv(
"DATABASE_URL",
"postgresql://breakpilot:breakpilot@postgres:5432/breakpilot",
)
# Strip SQLAlchemy dialect prefix (asyncpg needs plain postgresql://)
DATABASE_URL = _RAW_DB_URL.replace("postgresql+asyncpg://", "postgresql://")
# Strip search_path options (set via SET after connect)
if "options=" in DATABASE_URL:
DATABASE_URL = DATABASE_URL.split("?")[0] if "options=" in DATABASE_URL.split("?")[-1] else DATABASE_URL
_pool = None
@@ -28,7 +33,10 @@ async def get_pool():
global _pool
if _pool is None:
import asyncpg
_pool = await asyncpg.create_pool(DATABASE_URL, min_size=2, max_size=10)
_pool = await asyncpg.create_pool(
DATABASE_URL, min_size=2, max_size=10,
server_settings={"search_path": "lehrer,core,public"},
)
return _pool