From 2485450b5a4d215f97157c650af184c088e5aa2f Mon Sep 17 00:00:00 2001 From: stereodamage Date: Mon, 24 Apr 2023 03:56:05 +0400 Subject: [PATCH] Fix double EXPLAIN when calling explain on queryset --- silk/sql.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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())