diff --git a/django_mongodb_backend/functions.py b/django_mongodb_backend/functions.py index 750a548f8..464dddd6f 100644 --- a/django_mongodb_backend/functions.py +++ b/django_mongodb_backend/functions.py @@ -102,6 +102,8 @@ def extract(self, compiler, connection): def func(self, compiler, connection): lhs_mql = process_lhs(self, compiler, connection) + if self.function is None: + raise NotSupportedError(f"{self} may need an as_mql() method.") operator = MONGO_OPERATORS.get(self.__class__, self.function.lower()) return {f"${operator}": lhs_mql} diff --git a/tests/db_functions_/__init__.py b/tests/db_functions_/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/db_functions_/tests.py b/tests/db_functions_/tests.py new file mode 100644 index 000000000..23029d42e --- /dev/null +++ b/tests/db_functions_/tests.py @@ -0,0 +1,10 @@ +from django.db import NotSupportedError +from django.db.models import Func +from django.test import SimpleTestCase + + +class FuncTests(SimpleTestCase): + def test_no_as_mql(self): + msg = "Func() may need an as_mql() method." + with self.assertRaisesMessage(NotSupportedError, msg): + Func().as_mql(None, None)