Skip to content

Commit

Permalink
Fix double EXPLAIN when calling explain on queryset
Browse files Browse the repository at this point in the history
  • Loading branch information
stereodamage committed Jun 25, 2023
1 parent 274898f commit 10e8b7b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion silk/sql.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
import traceback

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

# currently we cannot use explain() method
# for queries other than `select`
prefixed_query = f"{prefix} {q}"
if re.match("EXPLAIN .*", q):
# to avoid "EXPLAIN EXPLAIN", do not add prefix
prefixed_query = q
else:
prefixed_query = f"{prefix} {q}"
with connection.cursor() as cur:
cur.execute(prefixed_query, params)
result = _unpack_explanation(cur.fetchall())
Expand Down

0 comments on commit 10e8b7b

Please sign in to comment.