From 6eec5f9b7a480ae33e6096cd070a0f9db5135f18 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 18 Mar 2021 03:27:33 +0100 Subject: [PATCH] Cut traceback on execute short Users don't care where in psycopg the error comes. --- psycopg3/psycopg3/cursor.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/psycopg3/psycopg3/cursor.py b/psycopg3/psycopg3/cursor.py index a6897fc98..2a8ad986d 100644 --- a/psycopg3/psycopg3/cursor.py +++ b/psycopg3/psycopg3/cursor.py @@ -502,8 +502,13 @@ class Cursor(BaseCursor["Connection"]): """ Execute a query or command to the database. """ - with self._conn.lock: - self._conn.wait(self._execute_gen(query, params, prepare=prepare)) + try: + with self._conn.lock: + self._conn.wait( + self._execute_gen(query, params, prepare=prepare) + ) + except e.Error as ex: + raise ex.with_traceback(None) return self def executemany(self, query: Query, params_seq: Sequence[Params]) -> None: @@ -629,10 +634,13 @@ class AsyncCursor(BaseCursor["AsyncConnection"]): *, prepare: Optional[bool] = None, ) -> "AsyncCursor": - async with self._conn.lock: - await self._conn.wait( - self._execute_gen(query, params, prepare=prepare) - ) + try: + async with self._conn.lock: + await self._conn.wait( + self._execute_gen(query, params, prepare=prepare) + ) + except e.Error as ex: + raise ex.with_traceback(None) return self async def executemany( -- 2.47.3