diff --git a/qdrant_client/conversions/conversion.py b/qdrant_client/conversions/conversion.py index 3377b9770..65f944f21 100644 --- a/qdrant_client/conversions/conversion.py +++ b/qdrant_client/conversions/conversion.py @@ -1473,7 +1473,9 @@ def convert_range(cls, model: rest.Range) -> grpc.Range: ) @classmethod - def convert_datetime(cls, model: datetime) -> Timestamp: + def convert_datetime(cls, model: Union[datetime, date]) -> Timestamp: + if isinstance(model, date) and not isinstance(model, datetime): + model = datetime.combine(model, datetime.min.time()) ts = Timestamp() ts.FromDatetime(model) return ts diff --git a/qdrant_client/local/payload_filters.py b/qdrant_client/local/payload_filters.py index 166daa4ba..0b47b7d37 100644 --- a/qdrant_client/local/payload_filters.py +++ b/qdrant_client/local/payload_filters.py @@ -109,7 +109,7 @@ def check_range(condition: models.Range, value: Any) -> bool: def check_datetime_range(condition: models.DatetimeRange, value: Any) -> bool: def make_condition_tz_aware(dt: Optional[Union[datetime, date]]) -> Optional[datetime]: - if isinstance(dt, date): + if isinstance(dt, date) and not isinstance(dt, datetime): dt = datetime.combine(dt, datetime.min.time()) if dt is None or dt.tzinfo is not None: diff --git a/tests/conversions/test_validate_conversions.py b/tests/conversions/test_validate_conversions.py index 35b4613e0..5c72cfcca 100644 --- a/tests/conversions/test_validate_conversions.py +++ b/tests/conversions/test_validate_conversions.py @@ -1,8 +1,9 @@ import inspect import logging import re -from datetime import datetime, timedelta, timezone +from datetime import date, datetime, timedelta, timezone from inspect import getmembers +from typing import Union import pytest from google.protobuf.json_format import MessageToDict @@ -264,14 +265,18 @@ def test_init_from_conversion(): datetime(2021, 1, 1, 0, 0, 0), datetime.utcnow(), datetime.now(), + date.today(), ], ) -def test_datetime_to_timestamp_conversions(dt: datetime): +def test_datetime_to_timestamp_conversions(dt: Union[datetime, date]): from qdrant_client.conversions.conversion import GrpcToRest, RestToGrpc rest_to_grpc = RestToGrpc.convert_datetime(dt) grpc_to_rest = GrpcToRest.convert_timestamp(rest_to_grpc) + if isinstance(dt, date) and not isinstance(dt, datetime): + dt = datetime.combine(dt, datetime.min.time()) + assert ( dt.utctimetuple() == grpc_to_rest.utctimetuple() ), f"Failed for {dt}, should be equal to {grpc_to_rest}"