Skip to content

Commit 4ce32f5

Browse files
authored
Merge pull request #1448 from sanders41/filterable-attributes
Fix type for filterable attributes
2 parents 13e6da0 + d7bf996 commit 4ce32f5

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

meilisearch_python_sdk/index.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,7 +3593,7 @@ async def reset_synonyms(self) -> TaskInfo:
35933593

35943594
return TaskInfo(**response.json())
35953595

3596-
async def get_filterable_attributes(self) -> list[str] | list[FilterableAttributes] | None:
3596+
async def get_filterable_attributes(self) -> list[str | FilterableAttributes] | None:
35973597
"""Get filterable attributes of the index.
35983598
35993599
Returns:
@@ -3616,22 +3616,22 @@ async def get_filterable_attributes(self) -> list[str] | list[FilterableAttribut
36163616

36173617
response_json = response.json()
36183618

3619-
if isinstance(response_json[0], str):
3620-
return response_json
3621-
3622-
filterable_attributes = []
3619+
filterable_attributes: list[str | FilterableAttributes] = []
36233620
for r in response_json:
3624-
filterable_attributes.append(
3625-
FilterableAttributes(
3626-
attribute_patterns=r["attributePatterns"],
3627-
features=FilterableAttributeFeatures(**r["features"]),
3621+
if isinstance(r, str):
3622+
filterable_attributes.append(r)
3623+
else:
3624+
filterable_attributes.append(
3625+
FilterableAttributes(
3626+
attribute_patterns=r["attributePatterns"],
3627+
features=FilterableAttributeFeatures(**r["features"]),
3628+
)
36283629
)
3629-
)
36303630

36313631
return filterable_attributes
36323632

36333633
async def update_filterable_attributes(
3634-
self, body: list[str] | list[FilterableAttributes], *, compress: bool = False
3634+
self, body: list[str | FilterableAttributes], *, compress: bool = False
36353635
) -> TaskInfo:
36363636
"""Update filterable attributes of the index.
36373637
@@ -7224,7 +7224,7 @@ def reset_synonyms(self) -> TaskInfo:
72247224

72257225
return TaskInfo(**response.json())
72267226

7227-
def get_filterable_attributes(self) -> list[str] | list[FilterableAttributes] | None:
7227+
def get_filterable_attributes(self) -> list[str | FilterableAttributes] | None:
72287228
"""Get filterable attributes of the index.
72297229
72307230
Returns:
@@ -7247,22 +7247,22 @@ def get_filterable_attributes(self) -> list[str] | list[FilterableAttributes] |
72477247

72487248
response_json = response.json()
72497249

7250-
if isinstance(response_json[0], str):
7251-
return response_json
7252-
7253-
filterable_attributes = []
7250+
filterable_attributes: list[str | FilterableAttributes] = []
72547251
for r in response_json:
7255-
filterable_attributes.append(
7256-
FilterableAttributes(
7257-
attribute_patterns=r["attributePatterns"],
7258-
features=FilterableAttributeFeatures(**r["features"]),
7252+
if isinstance(r, str):
7253+
filterable_attributes.append(r)
7254+
else:
7255+
filterable_attributes.append(
7256+
FilterableAttributes(
7257+
attribute_patterns=r["attributePatterns"],
7258+
features=FilterableAttributeFeatures(**r["features"]),
7259+
)
72597260
)
7260-
)
72617261

72627262
return filterable_attributes
72637263

72647264
def update_filterable_attributes(
7265-
self, body: list[str] | list[FilterableAttributes], *, compress: bool = False
7265+
self, body: list[str | FilterableAttributes], *, compress: bool = False
72667266
) -> TaskInfo:
72677267
"""Update filterable attributes of the index.
72687268

meilisearch_python_sdk/models/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class MeilisearchSettings(CamelBase):
167167
synonyms: JsonDict | None = None
168168
stop_words: list[str] | None = None
169169
ranking_rules: list[str] | None = None
170-
filterable_attributes: list[str] | list[FilterableAttributes] | None = None
170+
filterable_attributes: list[str | FilterableAttributes] | None = None
171171
distinct_attribute: str | None = None
172172
searchable_attributes: list[str] | None = None
173173
displayed_attributes: list[str] | None = None

tests/test_async_index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ async def test_get_filterable_attributes(async_empty_index):
586586
facet_search=True, filter=Filter(equality=True, comparison=False)
587587
),
588588
),
589+
"genre",
589590
],
590591
),
591592
)
@@ -594,7 +595,7 @@ async def test_update_filterable_attributes(compress, async_empty_index, filtera
594595
response = await index.update_filterable_attributes(filterable_attributes, compress=compress)
595596
await async_wait_for_task(index.http_client, response.task_uid)
596597
response = await index.get_filterable_attributes()
597-
assert sorted(response) == filterable_attributes
598+
assert response == filterable_attributes
598599

599600

600601
@pytest.mark.parametrize(

tests/test_index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ def test_get_filterable_attributes(empty_index):
574574
facet_search=True, filter=Filter(equality=True, comparison=False)
575575
),
576576
),
577+
"genre",
577578
],
578579
),
579580
)
@@ -582,7 +583,7 @@ def test_update_filterable_attributes(compress, empty_index, filterable_attribut
582583
response = index.update_filterable_attributes(filterable_attributes, compress=compress)
583584
wait_for_task(index.http_client, response.task_uid)
584585
response = index.get_filterable_attributes()
585-
assert sorted(response) == filterable_attributes
586+
assert response == filterable_attributes
586587

587588

588589
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)