diff --git a/test/collection/test_config_update.py b/test/collection/test_config_update.py index 073b645b9..2ed2053c3 100644 --- a/test/collection/test_config_update.py +++ b/test/collection/test_config_update.py @@ -1,4 +1,5 @@ -from typing import Optional +from datetime import timedelta +from typing import Optional, Union import pytest @@ -11,6 +12,29 @@ from weaviate.exceptions import WeaviateInvalidInputError +@pytest.mark.parametrize( + "offset,expected", + [(None, None), (0, 0), (timedelta(seconds=120), 120)], +) +def test_object_ttl_update_offset( + offset: Optional[Union[int, timedelta]], expected: Optional[int] +) -> None: + update = Reconfigure.ObjectTTL.delete_by_date_property( + filter_expired_objects=True, ttl_offset=offset + ) + assert update.defaultTtl == expected + merged = update.merge_with_existing( + { + "enabled": True, + "deleteOn": "expiresAt", + "defaultTtl": 3600, + "filterExpiredObjects": False, + } + ) + assert merged["defaultTtl"] == (3600 if expected is None else expected) + assert merged["filterExpiredObjects"] is True + + @pytest.mark.parametrize( "schema,should_error", [ diff --git a/weaviate/collections/classes/config_object_ttl.py b/weaviate/collections/classes/config_object_ttl.py index 86981f6dd..52c2158ef 100644 --- a/weaviate/collections/classes/config_object_ttl.py +++ b/weaviate/collections/classes/config_object_ttl.py @@ -145,13 +145,11 @@ def delete_by_date_property( Args: property_name: The name of the date property to use for object expiration. - ttl_offset: The time-to-live for objects relative to the date (seconds if integer). Can be negative for indicating that objects should expire before the date property value. + ttl_offset: The time-to-live for objects relative to the date (seconds if integer). Can be negative for indicating that objects should expire before the date property value. If `None`, omit the offset from the update. Pass `0` to explicitly reset it. filter_expired_objects: If enabled, exclude expired but not deleted objects from search results. """ if isinstance(ttl_offset, datetime.timedelta): ttl_offset = int(ttl_offset.total_seconds()) - if ttl_offset is None: - ttl_offset = 0 return ObjectTTLConfigUpdate( enabled=True, deleteOn=property_name,