diff --git a/django_mongodb/expressions.py b/django_mongodb/expressions.py index 15f1448a..5c736b07 100644 --- a/django_mongodb/expressions.py +++ b/django_mongodb/expressions.py @@ -210,6 +210,8 @@ def value(self, compiler, connection): # noqa: ARG001 return {"$literal": value} if isinstance(value, Decimal): return Decimal128(value) + if isinstance(value, datetime.datetime): + return value if isinstance(value, datetime.date): # Turn dates into datetimes since BSON doesn't support dates. return datetime.datetime.combine(value, datetime.datetime.min.time()) diff --git a/tests/expressions_/test_value.py b/tests/expressions_/test_value.py index 51ac2d28..c57c2f03 100644 --- a/tests/expressions_/test_value.py +++ b/tests/expressions_/test_value.py @@ -17,7 +17,7 @@ def test_date(self): def test_datetime(self): self.assertEqual( Value(datetime.datetime(2025, 1, 1, 9, 8, 7)).as_mql(None, None), - datetime.datetime(2025, 1, 1), + datetime.datetime(2025, 1, 1, 9, 8, 7), ) def test_decimal(self):