From: Daniele Varrazzo Date: Fri, 20 May 2022 08:55:17 +0000 (+0200) Subject: fix: shorter traceback even on COPY statement error X-Git-Tag: 3.1~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc1f666aa3565a42a05dd22fe69f98ffdd09d8c4;p=thirdparty%2Fpsycopg.git fix: shorter traceback even on COPY statement error The previous commit only addressed errors raised during transferring data, not the initial COPY statement. --- diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index f6a626b04..a2777e470 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -870,10 +870,10 @@ class Cursor(BaseCursor["Connection[Any]", Row]): :rtype: Copy """ - with self._conn.lock: - self._conn.wait(self._start_copy_gen(statement, params)) - try: + with self._conn.lock: + self._conn.wait(self._start_copy_gen(statement, params)) + with Copy(self) as copy: yield copy except e.Error as ex: diff --git a/psycopg/psycopg/cursor_async.py b/psycopg/psycopg/cursor_async.py index 316ce21e2..539678b94 100644 --- a/psycopg/psycopg/cursor_async.py +++ b/psycopg/psycopg/cursor_async.py @@ -196,10 +196,10 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]): """ :rtype: AsyncCopy """ - async with self._conn.lock: - await self._conn.wait(self._start_copy_gen(statement, params)) - try: + async with self._conn.lock: + await self._conn.wait(self._start_copy_gen(statement, params)) + async with AsyncCopy(self) as copy: yield copy except e.Error as ex: