diff --git a/api/chalicelib/core/alerts_processor.py b/api/chalicelib/core/alerts_processor.py index 89c3d58f3..4cf3fc507 100644 --- a/api/chalicelib/core/alerts_processor.py +++ b/api/chalicelib/core/alerts_processor.py @@ -203,7 +203,7 @@ def process(): logging.error(query) print("------------") logging.error(e) - cur = cur.recreate() + cur = cur.recreate(rollback=True) if len(notifications) > 0: cur.execute( cur.mogrify(f"""UPDATE public.Alerts diff --git a/api/chalicelib/utils/pg_client.py b/api/chalicelib/utils/pg_client.py index 1c4ef8560..69a5b5a8b 100644 --- a/api/chalicelib/utils/pg_client.py +++ b/api/chalicelib/utils/pg_client.py @@ -136,7 +136,12 @@ class PostgresClient: and not self.unlimited_query: postgreSQL_pool.putconn(self.connection) - def recreate_cursor(self): + def recreate_cursor(self, rollback=False): + if rollback: + try: + self.connection.rollback() + except Exception as error: + logging.error("Error while rollbacking connection for recreation", error) try: self.cursor.close() except Exception as error: