From c03c21510d19c31719de49a7e863f7e87ea336a7 Mon Sep 17 00:00:00 2001 From: Pierre-Yves David <pierre-yves.david@octobus.net> Date: Mon, 24 Mar 2025 15:33:42 +0100 Subject: [PATCH] use psycopg3's transaction in `BaseDb.transaction` There is a dedicated logic in psycopg3, so lets simply uses it. --- swh/core/db/__init__.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/swh/core/db/__init__.py b/swh/core/db/__init__.py index 122b363..4383454 100644 --- a/swh/core/db/__init__.py +++ b/swh/core/db/__init__.py @@ -184,14 +184,9 @@ class BaseDb: a psycopg cursor """ - with self.conn.cursor() as cur: - try: + with self.conn.transaction(): + with self.conn.cursor() as cur: yield cur - self.conn.commit() - except Exception: - if not self.conn.closed: - self.conn.rollback() - raise def copy_to( self, -- GitLab