Skip to content

Commit 791f329

Browse files
committed
Add mql check in EMF and EMFA unit test.
1 parent cf06a24 commit 791f329

File tree

4 files changed

+565
-33
lines changed

4 files changed

+565
-33
lines changed

django_mongodb_backend/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44

5+
from bson import Decimal128
56
from django.core.exceptions import EmptyResultSet, FullResultSet, ImproperlyConfigured
67
from django.db import DEFAULT_DB_ALIAS
78
from django.db.backends.base.base import BaseDatabaseWrapper
@@ -149,8 +150,13 @@ def range_match(a, b):
149150
conditions.append({a: {"$gte": b[0]}})
150151
if end is not None:
151152
conditions.append({a: {"$lte": b[1]}})
152-
if start is not None and end is not None and start > end:
153-
raise EmptyResultSet
153+
if start is not None and end is not None:
154+
if isinstance(start, Decimal128):
155+
start = start.to_decimal()
156+
if isinstance(end, Decimal128):
157+
end = end.to_decimal()
158+
if start > end:
159+
raise EmptyResultSet
154160
if not conditions:
155161
raise FullResultSet
156162
return {"$and": conditions}

django_mongodb_backend/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Not a public API."""
22

3-
from bson import SON, ObjectId
3+
from bson import SON, Decimal128, ObjectId
44

55

66
class MongoTestCaseMixin:
@@ -16,6 +16,6 @@ def assertAggregateQuery(self, query, expected_collection, expected_pipeline):
1616
self.assertEqual(operator, "aggregate")
1717
self.assertEqual(collection, expected_collection)
1818
self.assertEqual(
19-
eval(pipeline[:-1], {"SON": SON, "ObjectId": ObjectId}, {}), # noqa: S307
19+
eval(pipeline[:-1], {"SON": SON, "ObjectId": ObjectId, "Decimal128": Decimal128}, {}), # noqa: S307
2020
expected_pipeline,
2121
)

0 commit comments

Comments
 (0)