From: Daniele Varrazzo Date: Mon, 24 Nov 2025 14:27:51 +0000 (+0100) Subject: fix: don't throw errors on COPY_BOTH results X-Git-Tag: 3.3.0~10^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1219%2Fhead;p=thirdparty%2Fpsycopg.git fix: don't throw errors on COPY_BOTH results This change only allows to execute a `START_REPLICATION` command on a suitable configured database, i.e. the following commands would work: conn = psycopg.connect(DSN, replication="database", autocommit=True) conn.execute( """ START_REPLICATION SLOT "my_replication_slot" LOGICAL 0/0 (proto_version '1',publication_names 'my_publication') """) instead of gettgin an error such as "COPY cannot be used with this method". Please check https://github.com/psycopg/psycopg/issues/71#issuecomment-3393722855 for the description of the db configuration required to make this command work. No further support for logical replication is planned at this moment, but this change allows to play with replication without needing to go down at libpq level to execute replication commands. --- diff --git a/psycopg/psycopg/_cursor_base.py b/psycopg/psycopg/_cursor_base.py index 31eb6981c..18b2193f7 100644 --- a/psycopg/psycopg/_cursor_base.py +++ b/psycopg/psycopg/_cursor_base.py @@ -475,8 +475,12 @@ class BaseCursor(Generic[ConnectionType, Row]): raise e.InternalError("got no result from the query") for res in results: - status = res.status - if status != TUPLES_OK and status != COMMAND_OK and status != EMPTY_QUERY: + if ( + (status := res.status) != TUPLES_OK + and status != COMMAND_OK + and status != EMPTY_QUERY + and status != COPY_BOTH + ): self._raise_for_result(res) def _raise_for_result(self, result: PGresult) -> NoReturn: