Skip to content

Commit 35c0871

Browse files
committed
raise error for pattern lookups on UUIDField
1 parent 2e0d21a commit 35c0871

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.github/workflows/test-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
model_fields.test_charfield
7777
model_fields.test_floatfield
7878
model_fields.test_textfield
79-
model_fields.test_uuid.TestAsPrimaryKey.test_update_with_related_model_instance
79+
model_fields.test_uuid
8080
or_lookups
8181
8282
docs:

django_mongodb/features.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
class DatabaseFeatures(BaseDatabaseFeatures):
5+
supports_foreign_keys = False
56
# Not implemented: https://github.com/mongodb-labs/django-mongodb/issues/7
67
supports_transactions = False
78
uses_savepoints = False
@@ -33,6 +34,19 @@ class DatabaseFeatures(BaseDatabaseFeatures):
3334
"model_fields.test_datetimefield.DateTimeFieldTests.test_lookup_date_without_use_tz",
3435
# Empty queryset ORed (|) with another gives empty results.
3536
"or_lookups.tests.OrLookupsTests.test_empty_in",
37+
# Joins not supported.
38+
"model_fields.test_uuid.TestAsPrimaryKey.test_two_level_foreign_keys",
3639
}
3740

38-
django_test_skips = {}
41+
django_test_skips = {
42+
"Pattern lookups on UUIDField are not supported.": {
43+
"model_fields.test_uuid.TestQuerying.test_contains",
44+
"model_fields.test_uuid.TestQuerying.test_endswith",
45+
"model_fields.test_uuid.TestQuerying.test_filter_with_expr",
46+
"model_fields.test_uuid.TestQuerying.test_icontains",
47+
"model_fields.test_uuid.TestQuerying.test_iendswith",
48+
"model_fields.test_uuid.TestQuerying.test_iexact",
49+
"model_fields.test_uuid.TestQuerying.test_istartswith",
50+
"model_fields.test_uuid.TestQuerying.test_startswith",
51+
},
52+
}

django_mongodb/query.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from functools import wraps
33

44
from django.db import DatabaseError, IntegrityError, NotSupportedError
5+
from django.db.models.lookups import UUIDTextMixin
56
from django.db.models.query import QuerySet
67
from django.db.models.sql.where import OR, SubqueryConstraint
78
from django.utils.tree import Node
@@ -257,6 +258,9 @@ def _decode_child(self, child):
257258
Produce arguments suitable for add_filter from a WHERE tree leaf
258259
(a tuple).
259260
"""
261+
if isinstance(child, UUIDTextMixin):
262+
raise NotSupportedError("Pattern lookups on UUIDField are not supported.")
263+
260264
rhs, rhs_params = child.process_rhs(self.compiler, self.connection)
261265

262266
lookup_type = child.lookup_name

0 commit comments

Comments
 (0)