From e5bfd4f5eeb3d0e2fbde9c5c363194f5d3f48b1b Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Thu, 17 Jun 2021 14:29:10 +0200 Subject: [PATCH] Compatibility with psycopg2 2.9+ (#1970) the autocommit = True is ignored in the `with connection` block --- patroni/postgresql/connection.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/patroni/postgresql/connection.py b/patroni/postgresql/connection.py index 933ee89c..434bda59 100644 --- a/patroni/postgresql/connection.py +++ b/patroni/postgresql/connection.py @@ -40,7 +40,8 @@ class Connection(object): @contextmanager def get_connection_cursor(**kwargs): - with psycopg2.connect(**kwargs) as conn: - conn.autocommit = True - with conn.cursor() as cur: - yield cur + conn = psycopg2.connect(**kwargs) + conn.autocommit = True + with conn.cursor() as cur: + yield cur + conn.close()