Refs #32226 -- Fixed JSON format of QuerySet.explain() on PostgreSQL when format is uppercased.
Follow up to aba9c2de66
.
This commit is contained in:
parent
903702dfb1
commit
f4f2afeb45
|
@ -1434,9 +1434,8 @@ class SQLCompiler:
|
||||||
result = list(self.execute_sql())
|
result = list(self.execute_sql())
|
||||||
# Some backends return 1 item tuples with strings, and others return
|
# Some backends return 1 item tuples with strings, and others return
|
||||||
# tuples with integers and strings. Flatten them out into strings.
|
# tuples with integers and strings. Flatten them out into strings.
|
||||||
output_formatter = (
|
format_ = self.query.explain_info.format
|
||||||
json.dumps if self.query.explain_info.format == "json" else str
|
output_formatter = json.dumps if format_ and format_.lower() == "json" else str
|
||||||
)
|
|
||||||
for row in result[0]:
|
for row in result[0]:
|
||||||
if not isinstance(row, str):
|
if not isinstance(row, str):
|
||||||
yield " ".join(output_formatter(c) for c in row)
|
yield " ".join(output_formatter(c) for c in row)
|
||||||
|
|
|
@ -41,14 +41,16 @@ class ExplainTests(TestCase):
|
||||||
)
|
)
|
||||||
self.assertIsInstance(result, str)
|
self.assertIsInstance(result, str)
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
if format == "xml":
|
if not format:
|
||||||
|
continue
|
||||||
|
if format.lower() == "xml":
|
||||||
try:
|
try:
|
||||||
xml.etree.ElementTree.fromstring(result)
|
xml.etree.ElementTree.fromstring(result)
|
||||||
except xml.etree.ElementTree.ParseError as e:
|
except xml.etree.ElementTree.ParseError as e:
|
||||||
self.fail(
|
self.fail(
|
||||||
f"QuerySet.explain() result is not valid XML: {e}"
|
f"QuerySet.explain() result is not valid XML: {e}"
|
||||||
)
|
)
|
||||||
elif format == "json":
|
elif format.lower() == "json":
|
||||||
try:
|
try:
|
||||||
json.loads(result)
|
json.loads(result)
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
|
|
Loading…
Reference in New Issue