From 8cb0d5b2623145697b3d2e433b18319fcb4cd756 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 2 Jul 2024 15:55:23 +0200 Subject: [PATCH] make sure SQLAlchemy can handle the loaded dialect 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. --- src/nominatim_api/sql/async_core_library.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nominatim_api/sql/async_core_library.py b/src/nominatim_api/sql/async_core_library.py index c26846fb..f8e29749 100644 --- a/src/nominatim_api/sql/async_core_library.py +++ b/src/nominatim_api/sql/async_core_library.py @@ -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 -- 2.39.5