From 69969c85b919d37b8a6c1a790b26c0717563a59f Mon Sep 17 00:00:00 2001 From: openhands Date: Thu, 25 Dec 2025 03:37:32 +0000 Subject: [PATCH] Fix GCP async engine using wrong dbapi module (pg8000 instead of asyncpg) The _create_async_gcp_engine and _create_async_gcp_creator methods were incorrectly passing pg8000's dbapi to AsyncAdapt_asyncpg_connection. This caused errors when SQLAlchemy's asyncpg dialect tried to call asyncpg-specific error handling methods on the pg8000 module. The fix imports asyncpg directly and passes it as the dbapi parameter instead of extracting it from the sync pg8000 engine. Co-authored-by: openhands --- openhands/app_server/services/db_session_injector.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/openhands/app_server/services/db_session_injector.py b/openhands/app_server/services/db_session_injector.py index c59243af91..8295e1dd12 100644 --- a/openhands/app_server/services/db_session_injector.py +++ b/openhands/app_server/services/db_session_injector.py @@ -108,29 +108,26 @@ class DbSessionInjector(BaseModel, Injector[async_sessionmaker]): return engine async def _create_async_gcp_creator(self): + import asyncpg from sqlalchemy.dialects.postgresql.asyncpg import ( AsyncAdapt_asyncpg_connection, ) - engine = self._create_gcp_engine() - return AsyncAdapt_asyncpg_connection( - engine.dialect.dbapi, + asyncpg, await self._create_async_gcp_db_connection(), prepared_statement_cache_size=100, ) async def _create_async_gcp_engine(self): + import asyncpg from sqlalchemy.dialects.postgresql.asyncpg import ( AsyncAdapt_asyncpg_connection, ) - base_engine = self._create_gcp_engine() - dbapi = base_engine.dialect.dbapi - def adapted_creator(): return AsyncAdapt_asyncpg_connection( - dbapi, + asyncpg, await_only(self._create_async_gcp_db_connection()), prepared_statement_cache_size=100, )