Skip to content

Commit

Permalink
make Value encode UUID as string
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Aug 22, 2024
1 parent 97769ba commit 2d96786
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 3 additions & 0 deletions django_mongodb/expressions.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}


Expand Down
4 changes: 0 additions & 4 deletions django_mongodb/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 2d96786

Please sign in to comment.