Skip to content

Commit 10e8b7b

Browse files
committed
Fix double EXPLAIN when calling explain on queryset
1 parent 274898f commit 10e8b7b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

silk/sql.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import re
23
import traceback
34

45
from django.core.exceptions import EmptyResultSet
@@ -53,7 +54,11 @@ def _explain_query(connection, q, params):
5354

5455
# currently we cannot use explain() method
5556
# for queries other than `select`
56-
prefixed_query = f"{prefix} {q}"
57+
if re.match("EXPLAIN .*", q):
58+
# to avoid "EXPLAIN EXPLAIN", do not add prefix
59+
prefixed_query = q
60+
else:
61+
prefixed_query = f"{prefix} {q}"
5762
with connection.cursor() as cur:
5863
cur.execute(prefixed_query, params)
5964
result = _unpack_explanation(cur.fetchall())

0 commit comments

Comments
 (0)