Skip to content

Commit 017a567

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

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.db.models import Func
2+
from django.test import SimpleTestCase
3+
4+
5+
class FuncTests(SimpleTestCase):
6+
def test_no_as_mql(self):
7+
with self.assertRaisesMessage(ValueError, "Func() may need an as_mql() method."):
8+
Func().as_mql(None, None)

0 commit comments

Comments
 (0)