Skip to content

Commit 3173355

Browse files
committed
fix loss of time component in Value(datetime)
1 parent f91a5ea commit 3173355

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

django_mongodb/expressions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ def value(self, compiler, connection): # noqa: ARG001
210210
return {"$literal": value}
211211
if isinstance(value, Decimal):
212212
return Decimal128(value)
213+
if isinstance(value, datetime.datetime):
214+
return value
213215
if isinstance(value, datetime.date):
214216
# Turn dates into datetimes since BSON doesn't support dates.
215217
return datetime.datetime.combine(value, datetime.datetime.min.time())

tests/expressions_/test_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_date(self):
1717
def test_datetime(self):
1818
self.assertEqual(
1919
Value(datetime.datetime(2025, 1, 1, 9, 8, 7)).as_mql(None, None),
20-
datetime.datetime(2025, 1, 1),
20+
datetime.datetime(2025, 1, 1, 9, 8, 7),
2121
)
2222

2323
def test_decimal(self):

0 commit comments

Comments
 (0)