We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 19914cd commit c51ee08Copy full SHA for c51ee08
sentry_sdk/tracing_utils.py
@@ -354,7 +354,12 @@ def _format_sql(cursor, sql):
354
if hasattr(cursor, "mogrify"):
355
real_sql = cursor.mogrify(sql)
356
if isinstance(real_sql, bytes):
357
- real_sql = real_sql.decode(cursor.connection.encoding)
+ # 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")
363
except Exception:
364
real_sql = None
365
0 commit comments