]> 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:59:38 +0000 (01:59 +0200)
psycopg/psycopg/cursor.py
psycopg/psycopg/cursor_async.py

index ba15244cc233af16c3e130c0946826bb9bc45069..a7e81693b59d00563babeba37e5af1d98cb21487 100644 (file)
@@ -667,5 +667,8 @@ class Cursor(BaseCursor["Connection[Any]", Row]):
         with self._conn.lock:
             self._conn.wait(self._start_copy_gen(statement))
 
-        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)
index 4474e0c15615eca3e8bd76ddd1ea8e6556d8f4a4..182e5ffcceab19d6adacc816ec86a2570825e6b3 100644 (file)
@@ -154,5 +154,8 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         async with self._conn.lock:
             await self._conn.wait(self._start_copy_gen(statement))
 
-        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)