From 79c14f47f2068cd568ee8b50df79090f16a3f9c5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 20 May 2022 01:58:01 +0200 Subject: [PATCH] fix: shorter traceback on COPY error --- psycopg/psycopg/cursor.py | 7 +++++-- psycopg/psycopg/cursor_async.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) 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 ( -- 2.47.2