Skip to content

Commit ce26136

Browse files
committed
fix: validate reindex arguments before use (#2098 review)
Validate the tenants argument of update_property_index and rebuild_property_index as str | List[str] | None before the csv join so invalid input raises WeaviateInvalidInputError instead of a raw TypeError, matching the library's _validate_input idiom already applied to property_name/index_name. Document the WeaviateInvalidInputError in the affected docstrings and cover the validation with mock tests.
1 parent 6bcb4c5 commit ce26136

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

mock_tests/test_property_reindex.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,21 @@ def test_get_property_indexes(
393393
weaviate_139_mock.check_assertions()
394394

395395

396+
def test_property_reindex_invalid_input(
397+
weaviate_139_mock: HTTPServer, client_139: weaviate.WeaviateClient
398+
) -> None:
399+
"""Invalid argument types raise WeaviateInvalidInputError before any request is sent."""
400+
config = client_139.collections.use(COLLECTION).config
401+
402+
with pytest.raises(weaviate.exceptions.WeaviateInvalidInputError):
403+
config.update_property_index("age", "rangeFilters", tenants=123) # type: ignore
404+
with pytest.raises(weaviate.exceptions.WeaviateInvalidInputError):
405+
config.rebuild_property_index("age", "rangeFilters", tenants=[1, 2]) # type: ignore
406+
with pytest.raises(weaviate.exceptions.WeaviateInvalidInputError):
407+
config.cancel_property_index_task(123, "searchable") # type: ignore
408+
weaviate_139_mock.check_assertions()
409+
410+
396411
def test_property_reindex_unsupported_version(
397412
weaviate_client: weaviate.WeaviateClient,
398413
) -> None:

weaviate/collections/config/executor.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ def update_property_index(
804804
of the index when `wait_for_completion=True`.
805805
806806
Raises:
807+
weaviate.exceptions.WeaviateInvalidInputError: If the input parameters are invalid.
807808
weaviate.exceptions.WeaviateConnectionError: If the network connection to Weaviate fails.
808809
weaviate.exceptions.UnexpectedStatusCodeError: If Weaviate reports a non-OK status.
809810
weaviate.exceptions.ReindexFailedError: If `wait_for_completion=True` and the reindexing task failed.
@@ -814,6 +815,9 @@ def update_property_index(
814815
[_ValidateArgument(expected=[str], name="property_name", value=property_name)]
815816
)
816817
_validate_input([_ValidateArgument(expected=[str], name="index_name", value=index_name)])
818+
_validate_input(
819+
[_ValidateArgument(expected=[str, List[str], None], name="tenants", value=tenants)]
820+
)
817821

818822
path = self.__property_index_path(property_name, index_name)
819823
body: Dict[str, Any] = {}
@@ -912,6 +916,7 @@ def rebuild_property_index(
912916
of the index when `wait_for_completion=True`.
913917
914918
Raises:
919+
weaviate.exceptions.WeaviateInvalidInputError: If the input parameters are invalid.
915920
weaviate.exceptions.WeaviateConnectionError: If the network connection to Weaviate fails.
916921
weaviate.exceptions.UnexpectedStatusCodeError: If Weaviate reports a non-OK status.
917922
weaviate.exceptions.ReindexFailedError: If `wait_for_completion=True` and the reindexing task failed.
@@ -922,6 +927,9 @@ def rebuild_property_index(
922927
[_ValidateArgument(expected=[str], name="property_name", value=property_name)]
923928
)
924929
_validate_input([_ValidateArgument(expected=[str], name="index_name", value=index_name)])
930+
_validate_input(
931+
[_ValidateArgument(expected=[str, List[str], None], name="tenants", value=tenants)]
932+
)
925933

926934
path = self.__property_index_path(property_name, index_name) + "/rebuild"
927935
if isinstance(tenants, str):
@@ -991,6 +999,7 @@ def cancel_property_index_task(
991999
A `PropertyIndexTask` with status `CANCELLED` if a live task was cancelled or `NO_OP` otherwise.
9921000
9931001
Raises:
1002+
weaviate.exceptions.WeaviateInvalidInputError: If the input parameters are invalid.
9941003
weaviate.exceptions.WeaviateConnectionError: If the network connection to Weaviate fails.
9951004
weaviate.exceptions.UnexpectedStatusCodeError: If Weaviate reports a non-OK status.
9961005
"""

0 commit comments

Comments
 (0)