From: Daniele Varrazzo Date: Thu, 19 May 2022 23:58:01 +0000 (+0200) Subject: fix: shorter traceback on COPY error X-Git-Tag: 3.1~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79c14f47f2068cd568ee8b50df79090f16a3f9c5;p=thirdparty%2Fpsycopg.git fix: shorter traceback on COPY error --- diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index d211372dd..f6a626b04 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -873,8 +873,11 @@ class Cursor(BaseCursor["Connection[Any]", Row]): with self._conn.lock: self._conn.wait(self._start_copy_gen(statement, params)) - with Copy(self) as copy: - yield copy + try: + with Copy(self) as copy: + yield copy + except e.Error as ex: + raise ex.with_traceback(None) def _fetch_pipeline(self) -> None: if ( diff --git a/psycopg/psycopg/cursor_async.py b/psycopg/psycopg/cursor_async.py index fe2927b0d..316ce21e2 100644 --- a/psycopg/psycopg/cursor_async.py +++ b/psycopg/psycopg/cursor_async.py @@ -199,8 +199,11 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]): async with self._conn.lock: await self._conn.wait(self._start_copy_gen(statement, params)) - async with AsyncCopy(self) as copy: - yield copy + try: + async with AsyncCopy(self) as copy: + yield copy + except e.Error as ex: + raise ex.with_traceback(None) async def _fetch_pipeline(self) -> None: if (