Skip to content

Commit c51ee08

Browse files
committed
Avoid cursor.connection.encoding access to prevent connection pool interference
1 parent 19914cd commit c51ee08

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sentry_sdk/tracing_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,12 @@ def _format_sql(cursor, sql):
354354
if hasattr(cursor, "mogrify"):
355355
real_sql = cursor.mogrify(sql)
356356
if isinstance(real_sql, bytes):
357-
real_sql = real_sql.decode(cursor.connection.encoding)
357+
# Use UTF-8 as default, with latin1 fallback for edge cases
358+
try:
359+
real_sql = real_sql.decode("utf-8")
360+
except UnicodeDecodeError:
361+
# If UTF-8 fails, try latin1 as fallback
362+
real_sql = real_sql.decode("latin1", errors="replace")
358363
except Exception:
359364
real_sql = None
360365

0 commit comments

Comments
 (0)