Skip to content

Commit e56bf17

Browse files
committed
Fix error handling for unsupported lookups
1 parent b3a905f commit e56bf17

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

django_mongodb_backend/gis/lookups.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from django.contrib.gis.db.models.lookups import DistanceLookupFromFunction, GISLookup
2+
from django.db import NotSupportedError
23

34
from django_mongodb_backend.query_utils import process_lhs, process_rhs
45

56

67
def _gis_lookup(self, compiler, connection, as_expr=False):
78
lhs_mql = process_lhs(self, compiler, connection, as_expr=as_expr)
89
rhs_mql = process_rhs(self, compiler, connection, as_expr=as_expr)
9-
rhs_op = self.get_rhs_op(connection, rhs_mql)
10+
try:
11+
rhs_op = self.get_rhs_op(connection, rhs_mql)
12+
except KeyError:
13+
raise NotSupportedError(f"MongoDB does not support the '{self.lookup_name}' lookup.")
1014
return rhs_op.as_mql(lhs_mql, rhs_mql, self.rhs_params)
1115

1216

tests/gis_tests_/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
@skipUnlessDBFeature("gis_enabled")
99
class LookupTests(TestCase):
1010
def test_unsupported_lookups(self):
11-
msg = "MongoDB does not support the same_as lookup."
11+
msg = "MongoDB does not support the 'same_as' lookup."
1212
with self.assertRaisesMessage(NotSupportedError, msg):
1313
City.objects.get(point__same_as=Point(95, 30))

0 commit comments

Comments
 (0)