]> 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:58:19 +0000 (10:58 +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 a7e81693b59d00563babeba37e5af1d98cb21487..fec09a032762dc615c494df22b0edd9be2a70721 100644 (file)
@@ -664,10 +664,10 @@ class Cursor(BaseCursor["Connection[Any]", Row]):
 
         :rtype: Copy
         """
-        with self._conn.lock:
-            self._conn.wait(self._start_copy_gen(statement))
-
         try:
+            with self._conn.lock:
+                self._conn.wait(self._start_copy_gen(statement))
+
             with Copy(self) as copy:
                 yield copy
         except e.Error as ex:
index 182e5ffcceab19d6adacc816ec86a2570825e6b3..830a20b0d4e6f51517df57b932707cdfbc37802d 100644 (file)
@@ -151,10 +151,10 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         """
         :rtype: AsyncCopy
         """
-        async with self._conn.lock:
-            await self._conn.wait(self._start_copy_gen(statement))
-
         try:
+            async with self._conn.lock:
+                await self._conn.wait(self._start_copy_gen(statement))
+
             async with AsyncCopy(self) as copy:
                 yield copy
         except e.Error as ex: