From 06732928d96926f0cb106030d3ac42711c7f56f0 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 12 Apr 2024 14:11:22 +0200 Subject: [PATCH] fix: avoid explicit str() call when logging exception This was done as paranoia check for Sentry which might uses the repr of the exception even if we asked for `%s` and therefore might leak secrets, but frankly it's not our responsibility. https://github.com/getsentry/sentry-python/issues/2417 --- psycopg/psycopg/_connection_base.py | 2 +- psycopg/psycopg/_conninfo_attempts.py | 2 +- psycopg/psycopg/_conninfo_attempts_async.py | 2 +- psycopg/psycopg/connection.py | 2 +- psycopg/psycopg/connection_async.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/psycopg/psycopg/_connection_base.py b/psycopg/psycopg/_connection_base.py index 3d876f11e..44a7cb4b5 100644 --- a/psycopg/psycopg/_connection_base.py +++ b/psycopg/psycopg/_connection_base.py @@ -302,7 +302,7 @@ class BaseConnection(Generic[Row]): c = self.pgconn.get_cancel() c.cancel() except Exception as ex: - logger.warning("couldn't try to cancel query: %s", str(ex)) + logger.warning("couldn't try to cancel query: %s", ex) def _should_cancel(self) -> bool: """Check whether the current command should actually be cancelled when diff --git a/psycopg/psycopg/_conninfo_attempts.py b/psycopg/psycopg/_conninfo_attempts.py index 6f64f4ba1..8c75e60e3 100644 --- a/psycopg/psycopg/_conninfo_attempts.py +++ b/psycopg/psycopg/_conninfo_attempts.py @@ -41,7 +41,7 @@ def conninfo_attempts(params: ConnMapping) -> list[ConnDict]: try: attempts.extend(_resolve_hostnames(attempt)) except OSError as ex: - logger.debug("failed to resolve host %r: %s", attempt.get("host"), str(ex)) + logger.debug("failed to resolve host %r: %s", attempt.get("host"), ex) last_exc = ex if not attempts: diff --git a/psycopg/psycopg/_conninfo_attempts_async.py b/psycopg/psycopg/_conninfo_attempts_async.py index a549081e9..ff8b15d39 100644 --- a/psycopg/psycopg/_conninfo_attempts_async.py +++ b/psycopg/psycopg/_conninfo_attempts_async.py @@ -40,7 +40,7 @@ async def conninfo_attempts_async(params: ConnMapping) -> list[ConnDict]: try: attempts.extend(await _resolve_hostnames(attempt)) except OSError as ex: - logger.debug("failed to resolve host %r: %s", attempt.get("host"), str(ex)) + logger.debug("failed to resolve host %r: %s", attempt.get("host"), ex) last_exc = ex if not attempts: diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index ec334d122..04e7e73af 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -279,7 +279,7 @@ class Connection(BaseConnection[Row]): try: waiting.wait_conn(self._cancel_gen(), interval=_WAIT_INTERVAL) except Exception as ex: - logger.warning("couldn't try to cancel query: %s", str(ex)) + logger.warning("couldn't try to cancel query: %s", ex) else: self.cancel() diff --git a/psycopg/psycopg/connection_async.py b/psycopg/psycopg/connection_async.py index 8f36bf63e..faf3c512b 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -298,7 +298,7 @@ class AsyncConnection(BaseConnection[Row]): self._cancel_gen(), interval=_WAIT_INTERVAL ) except Exception as ex: - logger.warning("couldn't try to cancel query: %s", str(ex)) + logger.warning("couldn't try to cancel query: %s", ex) else: if True: # ASYNC -- 2.39.5