summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorWu Haotian <whtsky@gmail.com>2021-06-30 18:45:10 +0800
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-07-05 09:08:39 +0200
commitaba9c2de669dcc0278c7ffde7981be91801be00b (patch)
treed0bad959ff2d904f2f5da16c155daf48ee7bc8cf /django/db/models/sql
parentb3b04ad2111f1e3eb0640cd5d51d4391655317ce (diff)
Fixed #32226 -- Fixed JSON format of QuerySet.explain() on PostgreSQL.
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/compiler.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 136732bd0b..eda7fc3b5e 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -1,4 +1,5 @@
import collections
+import json
import re
from functools import partial
from itertools import chain
@@ -1250,9 +1251,10 @@ class SQLCompiler:
result = list(self.execute_sql())
# Some backends return 1 item tuples with strings, and others return
# tuples with integers and strings. Flatten them out into strings.
+ output_formatter = json.dumps if self.query.explain_format == 'json' else str
for row in result[0]:
if not isinstance(row, str):
- yield ' '.join(str(c) for c in row)
+ yield ' '.join(output_formatter(c) for c in row)
else:
yield row