From d1da53709f59cce1cbb9cf4fe6113b3ae68d28bf Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Fri, 21 Oct 2022 15:26:07 +0200 Subject: [PATCH] feat(chalice): recreate cursor --- api/chalicelib/utils/pg_client.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/chalicelib/utils/pg_client.py b/api/chalicelib/utils/pg_client.py index 8b9001649..1aa846669 100644 --- a/api/chalicelib/utils/pg_client.py +++ b/api/chalicelib/utils/pg_client.py @@ -141,6 +141,13 @@ class PostgresClient: and not self.unlimited_query: postgreSQL_pool.putconn(self.connection) + def recreate_cursor(self): + try: + self.cursor.close() + except Exception as error: + logging.error("Error while closing cursor for recreation", error) + self.cursor = self.connection.cursor(cursor_factory=psycopg2.extras.RealDictCursor) + def close(): pass