From 17d306be4531ccc268e24197ea8a63876abac8ee Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 13 Oct 2026 17:42:01 +0300 Subject: [PATCH 1/2] NodeConnection::execute does not catch exception now We do not suppress any exceptions in NodeConnection::execute. Amen. --- src/connection.py | 16 ++++++---------- tests/test_testgres_common.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/connection.py b/src/connection.py index ec455124..16ed38bf 100644 --- a/src/connection.py +++ b/src/connection.py @@ -1,6 +1,4 @@ # coding: utf-8 -import logging - # we support both pg8000 and psycopg2 try: import psycopg2 as pglib @@ -106,16 +104,14 @@ def rollback(self): def execute(self, query, *args): self.cursor.execute(query, args) - try: - # pg8000 might return tuples - res = [tuple(t) for t in self.cursor.fetchall()] - return res - except ProgrammingError: - return None - except Exception as e: - logging.error("Error executing query: {}\n {}".format(repr(e), query)) + + if self.cursor.description is None: return None + # pg8000 might return tuples + res = [tuple(t) for t in self.cursor.fetchall()] + return res + def close(self): self.cursor.close() self.connection.close() diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index 1cbc1109..6412ee8d 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -3338,6 +3338,28 @@ def test_node_app__make_empty_and_pgconf(self, node_svc: PostgresNodeService): assert node.status() == NodeStatus.Running return + def test_node_connection__execute( + self, + node_svc: PostgresNodeService, + ): + assert isinstance(node_svc, PostgresNodeService) + + with __class__.helper__get_node(node_svc) as node: + node.init() + node.start() + + with node.connect("postgres") as cn: + assert cn.execute("create table ttt (id integer);") is None + assert cn.execute("insert into ttt values(1);") is None + assert cn.execute("update ttt set id=2;") is None + assert cn.execute("select id from ttt;") == [(2, )] + assert cn.execute("delete from ttt where id=2;") is None + assert cn.execute("select id from ttt;") == [] + assert cn.execute("drop table ttt;") is None + pass + pass + return + @staticmethod def helper__get_node( node_svc: PostgresNodeService, From c746e16535980a3d75cd1b5cc5b02e55b947a624 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Wed, 14 Oct 2026 10:28:41 +0300 Subject: [PATCH 2/2] test_node_connection__execute is updated --- tests/test_testgres_common.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index 6412ee8d..1145d233 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -3353,6 +3353,8 @@ def test_node_connection__execute( assert cn.execute("insert into ttt values(1);") is None assert cn.execute("update ttt set id=2;") is None assert cn.execute("select id from ttt;") == [(2, )] + assert cn.execute("select id from ttt where id=%s;", '2') == [(2, )] + assert cn.execute("select id from ttt where id=%s and (id + 1) = %s;", '2', 3) == [(2, )] assert cn.execute("delete from ttt where id=2;") is None assert cn.execute("select id from ttt;") == [] assert cn.execute("drop table ttt;") is None