Skip to content

Commit c186f40

Browse files
committed
Avoid explaining MySQL keywords
1 parent 23917b8 commit c186f40

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

silk/sql.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import contextlib
12
import logging
23
import traceback
34

45
from django.apps import apps
5-
from django.db import connection
6+
from django.db import NotSupportedError, connection
67
from django.utils import timezone
78
from django.utils.encoding import force_str
89

@@ -83,16 +84,18 @@ def _should_wrap(self, sql_query):
8384
return False
8485

8586
# Must not try to explain 'EXPLAIN' queries or transaction stuff
86-
if any(
87-
sql_query.startswith(keyword)
88-
for keyword in [
89-
'SAVEPOINT',
90-
'RELEASE SAVEPOINT',
91-
'ROLLBACK TO SAVEPOINT',
92-
'PRAGMA',
93-
connection.ops.explain_query_prefix(),
94-
]
95-
):
87+
unexplainable_keywords = [
88+
'SAVEPOINT',
89+
'RELEASE SAVEPOINT',
90+
'ROLLBACK TO SAVEPOINT',
91+
'SET SESSION TRANSACTION',
92+
'SET CONSTRAINTS',
93+
'PRAGMA',
94+
]
95+
with contextlib.suppress(ValueError, NotSupportedError):
96+
unexplainable_keywords.append(connection.ops.explain_query_prefix())
97+
unexplainable_keywords.append(connection.ops.explain_query_prefix(analyze=True))
98+
if any(sql_query.startswith(keyword) for keyword in unexplainable_keywords):
9699
return False
97100

98101
for ignore_str in SilkyConfig().SILKY_IGNORE_QUERIES:

0 commit comments

Comments
 (0)