From: Daniele Varrazzo Date: Mon, 1 Sep 2025 16:06:43 +0000 (+0200) Subject: fix(copy): avoid sending copy data if an error is set X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c8cfb349668dc6e53d40fecf794c5eeeb2b3e1ee;p=thirdparty%2Fpsycopg.git fix(copy): avoid sending copy data if an error is set It would result in a partial message. The server seems to do the right thing anyway, but let's not waste its precious time. --- diff --git a/psycopg/psycopg/_copy.py b/psycopg/psycopg/_copy.py index 0934a63a2..02c92dab7 100644 --- a/psycopg/psycopg/_copy.py +++ b/psycopg/psycopg/_copy.py @@ -136,8 +136,9 @@ class Copy(BaseCopy["Connection[Any]"]): using the `Copy` object outside a block. """ if self._direction == COPY_IN: - if data := self.formatter.end(): - self._write(data) + if not exc: + if data := self.formatter.end(): + self._write(data) self.writer.finish(exc) self._finished = True else: diff --git a/psycopg/psycopg/_copy_async.py b/psycopg/psycopg/_copy_async.py index 05ec0f98f..95a8922fc 100644 --- a/psycopg/psycopg/_copy_async.py +++ b/psycopg/psycopg/_copy_async.py @@ -133,8 +133,9 @@ class AsyncCopy(BaseCopy["AsyncConnection[Any]"]): using the `Copy` object outside a block. """ if self._direction == COPY_IN: - if data := self.formatter.end(): - await self._write(data) + if not exc: + if data := self.formatter.end(): + await self._write(data) await self.writer.finish(exc) self._finished = True else: