Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions django_mongodb_backend/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.db.models.sql import compiler
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE, MULTI, SINGLE
from django.db.models.sql.datastructures import BaseTable
from django.db.models.sql.where import AND, OR, XOR, NothingNode, WhereNode
from django.db.models.sql.where import AND, OR, XOR, ExtraWhere, NothingNode, WhereNode
from django.utils.functional import cached_property
from pymongo import ASCENDING, DESCENDING

Expand Down Expand Up @@ -733,7 +733,7 @@ def _get_pushable_conditions(self):

@classmethod
def _collect_pushable(cls, expr, negated=False):
if expr is None or isinstance(expr, NothingNode):
if expr is None or isinstance(expr, (NothingNode, ExtraWhere)):
return {}
if isinstance(expr, WhereNode):
# Apply De Morgan: track negation so connectors are flipped
Expand Down
2 changes: 1 addition & 1 deletion django_mongodb_backend/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def get_pipeline(self):
return pipeline


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


Expand Down
3 changes: 3 additions & 0 deletions docs/releases/6.0.x.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Bug fixes
that references in migrations don't need to be adjusted if models are later
removed.

- Added a helpful ``NotSupportedError`` for ``QuerySet.extra(where=...)``
rather than crashing with a more obscure exception.

Deprecated features
-------------------

Expand Down
12 changes: 12 additions & 0 deletions tests/queries_/test_extra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import NotSupportedError
from django.test import TestCase

from .models import Author


class ExtraTests(TestCase):
def test_where(self):
author = Author.objects.create()
msg = "QuerySet.extra() is not supported on MongoDB."
with self.assertRaisesMessage(NotSupportedError, msg):
self.assertCountEqual(Author.objects.extra(where=["id=%s"], params=[author.id]), author)