]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: avoid explicit str() call when logging exception 785/head
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 12 Apr 2024 12:11:22 +0000 (14:11 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 12 Apr 2024 22:10:44 +0000 (00:10 +0200)
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
psycopg/psycopg/_conninfo_attempts.py
psycopg/psycopg/_conninfo_attempts_async.py
psycopg/psycopg/connection.py
psycopg/psycopg/connection_async.py

index 3d876f11ecc64e41e27ba361ff462d4c6143cb38..44a7cb4b596e0c01e65ee7ad4868d3d36891527b 100644 (file)
@@ -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
index 6f64f4ba1cc19d2793bea75142ac3c52148f8c04..8c75e60e3b22aaec72ee23d3d3420d10c5a867cc 100644 (file)
@@ -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:
index a549081e9578e1b2b6bc00cc26b0aaf65991de12..ff8b15d39f727de094bbe6d6087ccaa4eb497fba 100644 (file)
@@ -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:
index ec334d1227ca5f21e42a8eadbe8254b07dfee5b1..04e7e73af77454d664c8d1d54cf49d42456e2d3d 100644 (file)
@@ -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()
 
index 8f36bf63eaec8b367bc727367ce02844462f48b4..faf3c512bef56493cbf9aabd8c61e20fdfa93625 100644 (file)
@@ -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