File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -652,7 +652,7 @@ def explain_query(self):
652652 ** kwargs ,
653653 )
654654 # explain() expects a list and joins on a newline. Concatenate no lines
655- return [json_util .dumps (explain )]
655+ return [json_util .dumps (explain , indent = 4 )]
656656
657657
658658class SQLInsertCompiler (SQLCompiler ):
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ New features
1616- Added support for :ref: `database transactions <transactions >`.
1717- Added :class: `~.fields.PolymorphicEmbeddedModelField ` for storing a model
1818 instance that may be of more than one model class.
19+ - ``Query.explain() `` now returns a parseable JSON string instead of a list of
20+ formatted lines.
1921
20225.2.0 beta 1
2123============
Original file line number Diff line number Diff line change 1+ import json
2+
3+ from django .test import TestCase
4+
5+ from .models import Author
6+
7+
8+ class ExplainTests (TestCase ):
9+ def test_json_serializable (self ):
10+ explain = Author .objects .all ().explain ()
11+ self .assertIsInstance (explain , str )
12+
13+ explained_json = json .loads (explain )
14+ self .assertIsInstance (explained_json , dict )
You can’t perform that action at this time.
0 commit comments