diff --git a/django_mongodb/expressions.py b/django_mongodb/expressions.py index 9012279e..3b2eea2d 100644 --- a/django_mongodb/expressions.py +++ b/django_mongodb/expressions.py @@ -1,5 +1,6 @@ import datetime from decimal import Decimal +from uuid import UUID from bson import Decimal128 from django.core.exceptions import EmptyResultSet, FullResultSet @@ -110,6 +111,8 @@ def value(self, compiler, connection): # noqa: ARG001 elif isinstance(value, datetime.timedelta): # DurationField stores milliseconds rather than microseconds. value /= datetime.timedelta(milliseconds=1) + elif isinstance(value, UUID): + value = value.hex return {"$literal": value} diff --git a/django_mongodb/features.py b/django_mongodb/features.py index 07466977..2aa8217d 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -72,10 +72,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): "many_to_one.tests.ManyToOneTests.test_selects", # Incorrect JOIN with GenericRelation gives incorrect results. "aggregation_regress.tests.AggregationTests.test_aggregation_with_generic_reverse_relation", - # QuerySet.update() with UUIDField fails: - # "cannot encode native uuid.UUID with UuidRepresentation.UNSPECIFIED." - "expressions.tests.ValueTests.test_update_UUIDField_using_Value", - "expressions_case.tests.CaseExpressionTests.test_update_uuid", } # $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3. _django_test_expected_failures_bitwise = {