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
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:
@@ -126,15 +126,29 @@ class Settings(BaseSettings):
|
||||
``postgresql://`` and we need the ``+asyncpg`` driver suffix for
|
||||
the async engine. Normalise both cases here so the rest of the
|
||||
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://"):
|
||||
self.database_url = self.database_url.replace(
|
||||
"postgres://", "postgresql+asyncpg://", 1,
|
||||
)
|
||||
elif self.database_url.startswith("postgresql://"):
|
||||
self.database_url = self.database_url.replace(
|
||||
"postgresql://", "postgresql+asyncpg://", 1,
|
||||
)
|
||||
url = self.database_url
|
||||
|
||||
# Fix dialect scheme
|
||||
if url.startswith("postgres://"):
|
||||
url = url.replace("postgres://", "postgresql+asyncpg://", 1)
|
||||
elif url.startswith("postgresql://"):
|
||||
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
|
||||
|
||||
@model_validator(mode="after")
|
||||
|
||||
Reference in New Issue
Block a user