fix: strip sslmode from database URL (asyncpg doesn't support it)
Some checks failed
CI / API Lint (push) Has been cancelled
CI / Detect changes (push) Has been cancelled
CI / API Tests (push) Has been cancelled
CI / Scanner Lint (push) Has been cancelled
CI / Scanner Tests (push) Has been cancelled
CI / Banner Lint & Typecheck (push) Has been cancelled
CI / Banner Tests (push) Has been cancelled
CI / Banner Build (push) Has been cancelled
CI / Admin UI Typecheck (push) Has been cancelled
CI / Admin UI Tests (push) Has been cancelled
CI / Admin UI Build (push) Has been cancelled

This commit is contained in:
Ami
2026-04-21 14:54:18 +07:00
parent d3af80145b
commit 35ea49d6d2

View File

@@ -126,15 +126,29 @@ class Settings(BaseSettings):
``postgresql://`` and we need the ``+asyncpg`` driver suffix for ``postgresql://`` and we need the ``+asyncpg`` driver suffix for
the async engine. Normalise both cases here so the rest of the the async engine. Normalise both cases here so the rest of the
codebase can always assume ``postgresql+asyncpg://``. codebase can always assume ``postgresql+asyncpg://``.
Also strips ``sslmode`` from query strings — asyncpg does not
accept this psycopg2 parameter and would raise TypeError.
""" """
if self.database_url.startswith("postgres://"): url = self.database_url
self.database_url = self.database_url.replace(
"postgres://", "postgresql+asyncpg://", 1, # Fix dialect scheme
) if url.startswith("postgres://"):
elif self.database_url.startswith("postgresql://"): url = url.replace("postgres://", "postgresql+asyncpg://", 1)
self.database_url = self.database_url.replace( elif url.startswith("postgresql://"):
"postgresql://", "postgresql+asyncpg://", 1, url = url.replace("postgresql://", "postgresql+asyncpg://", 1)
)
# Strip sslmode from query string (asyncpg doesn't support it)
if "?sslmode=" in url or "&sslmode=" in url:
from urllib.parse import urlparse, urlencode, parse_qs
parsed = urlparse(url)
params = parse_qs(parsed.query, keep_blank_values=True)
params.pop("sslmode", None)
query = urlencode(params, doseq=True)
url = parsed._replace(query=query).geturl()
self.database_url = url
return self return self
@model_validator(mode="after") @model_validator(mode="after")