Skip to content

Commit 0297de2

Browse files
committed
provided docs update and tests
1 parent d1e84fc commit 0297de2

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

django_mongodb_backend/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

658658
class SQLInsertCompiler(SQLCompiler):

docs/source/releases/5.2.x.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

2022
5.2.0 beta 1
2123
============

tests/queries_/test_explain.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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)

0 commit comments

Comments
 (0)