Skip to content

Commit

Permalink
make sure SQLAlchemy can handle the loaded dialect
Browse files Browse the repository at this point in the history
The psycopg dialect was only added in SQLAlchemy 2.0. To avoid loading
errors when SQLAlchemy 1.4 is installed together with psycopg3,
check that the dialect is really available.
  • Loading branch information
lonvia committed Jul 2, 2024
1 parent e51973f commit 8cb0d5b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/nominatim_api/sql/async_core_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
"""
Import the base library to use with asynchronous SQLAlchemy.
"""
# pylint: disable=invalid-name
# pylint: disable=invalid-name, ungrouped-imports, unused-import

from typing import Any

try:
import sqlalchemy.dialects.postgresql.psycopg
import psycopg
PGCORE_LIB = 'psycopg'
PGCORE_ERROR: Any = psycopg.Error
except ModuleNotFoundError:
import sqlalchemy.dialects.postgresql.asyncpg
import asyncpg
PGCORE_LIB = 'asyncpg'
PGCORE_ERROR = asyncpg.PostgresError

0 comments on commit 8cb0d5b

Please sign in to comment.