Skip to content

Commit b087d33

Browse files
committed
INTPYTHON-935 Fix QuerySet.extra(where=...) crash
1 parent 1ee3e1d commit b087d33

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

django_mongodb_backend/compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from django.db.models.sql import compiler
1414
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE, MULTI, SINGLE
1515
from django.db.models.sql.datastructures import BaseTable
16-
from django.db.models.sql.where import AND, OR, XOR, NothingNode, WhereNode
16+
from django.db.models.sql.where import AND, OR, XOR, ExtraWhere, NothingNode, WhereNode
1717
from django.utils.functional import cached_property
1818
from pymongo import ASCENDING, DESCENDING
1919

@@ -733,7 +733,7 @@ def _get_pushable_conditions(self):
733733

734734
@classmethod
735735
def _collect_pushable(cls, expr, negated=False):
736-
if expr is None or isinstance(expr, NothingNode):
736+
if expr is None or isinstance(expr, (NothingNode, ExtraWhere)):
737737
return {}
738738
if isinstance(expr, WhereNode):
739739
# Apply De Morgan: track negation so connectors are flipped

django_mongodb_backend/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def get_pipeline(self):
166166
return pipeline
167167

168168

169-
def extra_where(self, compiler, connection): # noqa: ARG001
169+
def extra_where(self, compiler, connection, as_expr=False): # noqa: ARG001
170170
raise NotSupportedError("QuerySet.extra() is not supported on MongoDB.")
171171

172172

docs/releases/6.0.x.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Bug fixes
3535
that references in migrations don't need to be adjusted if models are later
3636
removed.
3737

38+
- Fixed ``QuerySet.extra(where=...)`` crash (rather than raising
39+
``NotSupportedError``).
40+
3841
Deprecated features
3942
-------------------
4043

tests/queries_/test_extra.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.db import NotSupportedError
2+
from django.test import TestCase
3+
4+
from .models import Author
5+
6+
7+
class ExtraTests(TestCase):
8+
def test_where(self):
9+
author = Author.objects.create()
10+
msg = "QuerySet.extra() is not supported on MongoDB."
11+
with self.assertRaisesMessage(NotSupportedError, msg):
12+
self.assertCountEqual(Author.objects.extra(where=["id=%s"], params=[author.id]), author)

0 commit comments

Comments
 (0)