From d989bd3e8359565ddeb61602c18fb6b3c8264fec Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Wed, 14 Sep 2022 14:04:41 +0100 Subject: [PATCH] feat(chalice): catch unkeyed connection --- api/chalicelib/utils/pg_client.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/chalicelib/utils/pg_client.py b/api/chalicelib/utils/pg_client.py index 39a5e2e4b..1ec1f2a19 100644 --- a/api/chalicelib/utils/pg_client.py +++ b/api/chalicelib/utils/pg_client.py @@ -38,8 +38,15 @@ class ORThreadedConnectionPool(psycopg2.pool.ThreadedConnectionPool): raise e def putconn(self, *args, **kwargs): - super().putconn(*args, **kwargs) - self._semaphore.release() + try: + super().putconn(*args, **kwargs) + self._semaphore.release() + except psycopg2.pool.PoolError as e: + if str(e) == "trying to put unkeyed connection": + print("!!! trying to put unkeyed connection") + print(f"env-PG_POOL:{config('PG_POOL', cast=bool, default=None)}") + return + raise e postgreSQL_pool: ORThreadedConnectionPool = None