Skip to content

Commit 4de9516

Browse files
committed
Add a better error message when a Func is missing as_mql()
1 parent ef82d68 commit 4de9516

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

django_mongodb_backend/functions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ def extract(self, compiler, connection):
102102

103103
def func(self, compiler, connection):
104104
lhs_mql = process_lhs(self, compiler, connection)
105+
if self.function is None:
106+
raise NotSupportedError(f"{self} may need an as_mql() method.")
105107
operator = MONGO_OPERATORS.get(self.__class__, self.function.lower())
106108
return {f"${operator}": lhs_mql}
107109

tests/db_functions_/__init__.py

Whitespace-only changes.

tests/db_functions_/tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.db import NotSupportedError
2+
from django.db.models import Func
3+
from django.test import SimpleTestCase
4+
5+
6+
class FuncTests(SimpleTestCase):
7+
def test_no_as_mql(self):
8+
msg = "Func() may need an as_mql() method."
9+
with self.assertRaisesMessage(NotSupportedError, msg):
10+
Func().as_mql(None, None)

0 commit comments

Comments
 (0)