Skip to content

Commit 2d96786

Browse files
committed
make Value encode UUID as string
1 parent 97769ba commit 2d96786

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

django_mongodb/expressions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
from decimal import Decimal
3+
from uuid import UUID
34

45
from bson import Decimal128
56
from django.core.exceptions import EmptyResultSet, FullResultSet
@@ -110,6 +111,8 @@ def value(self, compiler, connection): # noqa: ARG001
110111
elif isinstance(value, datetime.timedelta):
111112
# DurationField stores milliseconds rather than microseconds.
112113
value /= datetime.timedelta(milliseconds=1)
114+
elif isinstance(value, UUID):
115+
value = value.hex
113116
return {"$literal": value}
114117

115118

django_mongodb/features.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
7272
"many_to_one.tests.ManyToOneTests.test_selects",
7373
# Incorrect JOIN with GenericRelation gives incorrect results.
7474
"aggregation_regress.tests.AggregationTests.test_aggregation_with_generic_reverse_relation",
75-
# QuerySet.update() with UUIDField fails:
76-
# "cannot encode native uuid.UUID with UuidRepresentation.UNSPECIFIED."
77-
"expressions.tests.ValueTests.test_update_UUIDField_using_Value",
78-
"expressions_case.tests.CaseExpressionTests.test_update_uuid",
7975
}
8076
# $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3.
8177
_django_test_expected_failures_bitwise = {

0 commit comments

Comments
 (0)