]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: shorter traceback on COPY error
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 19 May 2022 23:58:01 +0000 (01:58 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 19 May 2022 23:58:01 +0000 (01:58 +0200)
psycopg/psycopg/cursor.py
psycopg/psycopg/cursor_async.py

index d211372dd8ccecaa0179840728074c5a95714b4b..f6a626b044d588fd007157933f8deae3e5ee7daa 100644 (file)
@@ -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 (
index fe2927b0dfe1e72fe6ab67fda58caa5476480a15..316ce21e2286309fe6ac031e056a7c3934e9406f 100644 (file)
@@ -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 (