Skip to content

Commit ed1c470

Browse files
committed
Make explain() yield a mongodb-compatible dumped json
1 parent e91193b commit ed1c470

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

django_mongodb_backend/compiler.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pprint
33
from collections import defaultdict
44

5-
from bson import SON
5+
from bson import json_util, SON
66
from django.core.exceptions import EmptyResultSet, FieldError, FullResultSet
77
from django.db import IntegrityError, NotSupportedError
88
from django.db.models import Count
@@ -652,12 +652,8 @@ def explain_query(self):
652652
{"aggregate": self.collection_name, "pipeline": pipeline, "cursor": {}},
653653
**kwargs,
654654
)
655-
# Generate the output: a list of lines that Django joins with newlines.
656-
result = []
657-
for key, value in explain.items():
658-
formatted_value = pprint.pformat(value, indent=4)
659-
result.append(f"{key}: {formatted_value}")
660-
return result
655+
# explain() expects a list and joins on a newline. Concatenate no lines
656+
return [json_util.dumps(explain)]
661657

662658

663659
class SQLInsertCompiler(SQLCompiler):

0 commit comments

Comments
 (0)