Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions project/tests/test_execute_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def test_explain_simple(self):
sql.connection.ops.explain_query_prefix.return_value = prefix
execute_sql(sql)
self.assertNotIn(prefix, params)
params = tuple(force_str(param) for param in params)
mock_cursor.execute.assert_called_once_with(f"{prefix} {_simple_mock_query_sql}", params)

def test_explain_unicode(self):
Expand All @@ -144,7 +143,6 @@ def test_explain_unicode(self):
sql.connection.ops.explain_query_prefix.return_value = prefix
execute_sql(sql)
self.assertNotIn(prefix, params)
params = tuple(force_str(param) for param in params)
mock_cursor.execute.assert_called_once_with(f"{prefix} {_simple_mock_query_sql}", params)

def test_explain_non_unicode(self):
Expand Down
13 changes: 1 addition & 12 deletions silk/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,7 @@ def _explain_query(connection, q, params):
else:
prefixed_query = f"{prefix} {q}"
with connection.cursor() as cur:
try:
params_str = tuple(force_str(param) for param in params)
except UnicodeDecodeError:
# Sometimes `force_str` can still raise a UnicodeDecodeError
# Reference: https://github.com/jazzband/django-silk/issues?q=encoding
Logger.error(
"UnicodeDecodeError while trying to explain query: %s. "
"This could be caused by a non-UTF-8 encoded parameter.",
q
)
return None
cur.execute(prefixed_query, params_str)
cur.execute(prefixed_query, params)
result = _unpack_explanation(cur.fetchall())
return '\n'.join(result)
Comment on lines 63 to 64
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be that these lines are actually the part that's problematic for non-UTF-8 data? Looking at #798 and specifically the initial commit of 584a6e2, it was wrapping all three lines here in the try/except at first.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at #819 , the error people are getting seem to be an error from the postgresql database itself. That would only happen in the cur.execute() so the exception happens before these two lines are even reached.

return None
Expand Down