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):
652
652
** kwargs ,
653
653
)
654
654
# 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 )]
656
656
657
657
658
658
class SQLInsertCompiler (SQLCompiler ):
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ New features
16
16
- Added support for :ref: `database transactions <transactions >`.
17
17
- Added :class: `~.fields.PolymorphicEmbeddedModelField ` for storing a model
18
18
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.
19
21
20
22
5.2.0 beta 1
21
23
============
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