Skip to content

Commit 5c576fa

Browse files
committed
Issue #89: Don't silently fail when using multiple $or conditions
1 parent 5562cee commit 5c576fa

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

django_mongodb_engine/compiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def add_filters(self, filters, query=None):
136136
query = self._mongo_query
137137

138138
if filters.connector == OR:
139+
assert '$or' not in query, "Multiple ORs are not supported"
139140
or_conditions = query['$or'] = []
140141

141142
if filters.negated:
@@ -153,7 +154,7 @@ def add_filters(self, filters, query=None):
153154
raise DatabaseError("Nested ORs are not supported")
154155

155156
if filters.connector == OR and filters.negated:
156-
raise NotImplementedError("Negated ORs are not implemented")
157+
raise NotImplementedError("Negated ORs are not supported")
157158

158159
self.add_filters(child, query=subquery)
159160

tests/mongodb/tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.core.management import call_command
33
from django.db import connection, connections
44
from django.db.utils import DatabaseError, IntegrityError
5+
from django.db.models import Q
56
from django.contrib.sites.models import Site
67

78
from pymongo.objectid import InvalidId
@@ -170,6 +171,11 @@ def test_multiple_exclude_random(self):
170171
q = getattr(q, 'filter' if randint(0, 1) else 'exclude')(raw=i)
171172
list(q)
172173

174+
def test_issue_89(self):
175+
query = [Q(raw='a') | Q(raw='b'),
176+
Q(raw='c') | Q(raw='d')]
177+
self.assertRaises(AssertionError, RawModel.objects.get, *query)
178+
173179
class DatabaseOptionTests(TestCase):
174180
""" Tests for MongoDB-specific database options """
175181

0 commit comments

Comments
 (0)