diff --git a/meilisearch_python_sdk/index.py b/meilisearch_python_sdk/index.py index 58fc6a07..df5b5316 100644 --- a/meilisearch_python_sdk/index.py +++ b/meilisearch_python_sdk/index.py @@ -3593,7 +3593,7 @@ async def reset_synonyms(self) -> TaskInfo: return TaskInfo(**response.json()) - async def get_filterable_attributes(self) -> list[str] | list[FilterableAttributes] | None: + async def get_filterable_attributes(self) -> list[str | FilterableAttributes] | None: """Get filterable attributes of the index. Returns: @@ -3616,22 +3616,22 @@ async def get_filterable_attributes(self) -> list[str] | list[FilterableAttribut response_json = response.json() - if isinstance(response_json[0], str): - return response_json - - filterable_attributes = [] + filterable_attributes: list[str | FilterableAttributes] = [] for r in response_json: - filterable_attributes.append( - FilterableAttributes( - attribute_patterns=r["attributePatterns"], - features=FilterableAttributeFeatures(**r["features"]), + if isinstance(r, str): + filterable_attributes.append(r) + else: + filterable_attributes.append( + FilterableAttributes( + attribute_patterns=r["attributePatterns"], + features=FilterableAttributeFeatures(**r["features"]), + ) ) - ) return filterable_attributes async def update_filterable_attributes( - self, body: list[str] | list[FilterableAttributes], *, compress: bool = False + self, body: list[str | FilterableAttributes], *, compress: bool = False ) -> TaskInfo: """Update filterable attributes of the index. @@ -7224,7 +7224,7 @@ def reset_synonyms(self) -> TaskInfo: return TaskInfo(**response.json()) - def get_filterable_attributes(self) -> list[str] | list[FilterableAttributes] | None: + def get_filterable_attributes(self) -> list[str | FilterableAttributes] | None: """Get filterable attributes of the index. Returns: @@ -7247,22 +7247,22 @@ def get_filterable_attributes(self) -> list[str] | list[FilterableAttributes] | response_json = response.json() - if isinstance(response_json[0], str): - return response_json - - filterable_attributes = [] + filterable_attributes: list[str | FilterableAttributes] = [] for r in response_json: - filterable_attributes.append( - FilterableAttributes( - attribute_patterns=r["attributePatterns"], - features=FilterableAttributeFeatures(**r["features"]), + if isinstance(r, str): + filterable_attributes.append(r) + else: + filterable_attributes.append( + FilterableAttributes( + attribute_patterns=r["attributePatterns"], + features=FilterableAttributeFeatures(**r["features"]), + ) ) - ) return filterable_attributes def update_filterable_attributes( - self, body: list[str] | list[FilterableAttributes], *, compress: bool = False + self, body: list[str | FilterableAttributes], *, compress: bool = False ) -> TaskInfo: """Update filterable attributes of the index. diff --git a/meilisearch_python_sdk/models/settings.py b/meilisearch_python_sdk/models/settings.py index 3fa30326..dd60e42d 100644 --- a/meilisearch_python_sdk/models/settings.py +++ b/meilisearch_python_sdk/models/settings.py @@ -167,7 +167,7 @@ class MeilisearchSettings(CamelBase): synonyms: JsonDict | None = None stop_words: list[str] | None = None ranking_rules: list[str] | None = None - filterable_attributes: list[str] | list[FilterableAttributes] | None = None + filterable_attributes: list[str | FilterableAttributes] | None = None distinct_attribute: str | None = None searchable_attributes: list[str] | None = None displayed_attributes: list[str] | None = None diff --git a/tests/test_async_index.py b/tests/test_async_index.py index 24cee964..4b909ed5 100644 --- a/tests/test_async_index.py +++ b/tests/test_async_index.py @@ -586,6 +586,7 @@ async def test_get_filterable_attributes(async_empty_index): facet_search=True, filter=Filter(equality=True, comparison=False) ), ), + "genre", ], ), ) @@ -594,7 +595,7 @@ async def test_update_filterable_attributes(compress, async_empty_index, filtera response = await index.update_filterable_attributes(filterable_attributes, compress=compress) await async_wait_for_task(index.http_client, response.task_uid) response = await index.get_filterable_attributes() - assert sorted(response) == filterable_attributes + assert response == filterable_attributes @pytest.mark.parametrize( diff --git a/tests/test_index.py b/tests/test_index.py index 40c49c4b..279d3a73 100644 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -574,6 +574,7 @@ def test_get_filterable_attributes(empty_index): facet_search=True, filter=Filter(equality=True, comparison=False) ), ), + "genre", ], ), ) @@ -582,7 +583,7 @@ def test_update_filterable_attributes(compress, empty_index, filterable_attribut response = index.update_filterable_attributes(filterable_attributes, compress=compress) wait_for_task(index.http_client, response.task_uid) response = index.get_filterable_attributes() - assert sorted(response) == filterable_attributes + assert response == filterable_attributes @pytest.mark.parametrize(