]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: shorter traceback even on COPY statement error
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 20 May 2022 08:55:17 +0000 (10:55 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 20 May 2022 08:55:17 +0000 (10:55 +0200)
The previous commit only addressed errors raised during transferring
data, not the initial COPY statement.

psycopg/psycopg/cursor.py
psycopg/psycopg/cursor_async.py

index f6a626b044d588fd007157933f8deae3e5ee7daa..a2777e470026d4c5da9ebbf5e204545fd08a749b 100644 (file)
@@ -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:
index 316ce21e2286309fe6ac031e056a7c3934e9406f..539678b94918dd41d08006bf8a22f9c756c3c20b 100644 (file)
@@ -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: