]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: don't throw errors on COPY_BOTH results 1219/head
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 24 Nov 2025 14:27:51 +0000 (15:27 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 24 Nov 2025 18:34:30 +0000 (19:34 +0100)
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')
        """)
    <psycopg.Cursor [COPY_BOTH] [ACTIVE] at 0x...>

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.

psycopg/psycopg/_cursor_base.py

index 31eb6981c891c407f365fdf646c1de3546ee7c67..18b2193f79e948cfa3d3d484ad845d6899392465 100644 (file)
@@ -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: