mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
Fixed #35294 -- Fixed TEXT format of QuerySet.explain() for long plans.
co-authored-by: Gordon <gordon.wrigley@gmail.com> co-authored-by: Simon Charette <charette.s@gmail.com>
This commit is contained in:
parent
593067a8ee
commit
cbf1e87398
@ -1621,11 +1621,12 @@ class SQLCompiler:
|
|||||||
# tuples with integers and strings. Flatten them out into strings.
|
# tuples with integers and strings. Flatten them out into strings.
|
||||||
format_ = self.query.explain_info.format
|
format_ = self.query.explain_info.format
|
||||||
output_formatter = json.dumps if format_ and format_.lower() == "json" else str
|
output_formatter = json.dumps if format_ and format_.lower() == "json" else str
|
||||||
for row in result[0]:
|
for row in result:
|
||||||
if not isinstance(row, str):
|
for value in row:
|
||||||
yield " ".join(output_formatter(c) for c in row)
|
if not isinstance(value, str):
|
||||||
else:
|
yield " ".join([output_formatter(c) for c in value])
|
||||||
yield row
|
else:
|
||||||
|
yield value
|
||||||
|
|
||||||
|
|
||||||
class SQLInsertCompiler(SQLCompiler):
|
class SQLInsertCompiler(SQLCompiler):
|
||||||
|
@ -96,6 +96,15 @@ class ExplainTests(TestCase):
|
|||||||
option = "{} {}".format(name.upper(), "true" if value else "false")
|
option = "{} {}".format(name.upper(), "true" if value else "false")
|
||||||
self.assertIn(option, captured_queries[0]["sql"])
|
self.assertIn(option, captured_queries[0]["sql"])
|
||||||
|
|
||||||
|
def test_multi_page_text_explain(self):
|
||||||
|
if "TEXT" not in connection.features.supported_explain_formats:
|
||||||
|
self.skipTest("This backend does not support TEXT format.")
|
||||||
|
|
||||||
|
base_qs = Tag.objects.order_by()
|
||||||
|
qs = base_qs.filter(name="test").union(*[base_qs for _ in range(100)])
|
||||||
|
result = qs.explain(format="text")
|
||||||
|
self.assertGreaterEqual(result.count("\n"), 100)
|
||||||
|
|
||||||
def test_option_sql_injection(self):
|
def test_option_sql_injection(self):
|
||||||
qs = Tag.objects.filter(name="test")
|
qs = Tag.objects.filter(name="test")
|
||||||
options = {"SUMMARY true) SELECT 1; --": True}
|
options = {"SUMMARY true) SELECT 1; --": True}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user