diff --git a/silk/sql.py b/silk/sql.py index cc54276f..bceaad00 100644 --- a/silk/sql.py +++ b/silk/sql.py @@ -1,4 +1,5 @@ import logging +import re import traceback from django.core.exceptions import EmptyResultSet @@ -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())