Skip to content

Commit 07b8d93

Browse files
authored
fix: fix doc store mixin to use correct doc store method (#12045)
1 parent f1c9630 commit 07b8d93

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

haystack/testing/document_store.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,24 +1052,27 @@ def test_count_unique_metadata_by_filter_with_filter(document_store: DocumentSto
10521052

10531053
@staticmethod
10541054
def test_count_unique_metadata_by_filter_with_multiple_filters(document_store: DocumentStore):
1055-
"""Test counting with multiple filters"""
1055+
"""Test count_unique_metadata_by_filter() with multiple filters."""
10561056
docs = [
1057-
Document(content="Doc 1", meta={"category": "A", "year": 2023}),
1058-
Document(content="Doc 2", meta={"category": "A", "year": 2024}),
1059-
Document(content="Doc 3", meta={"category": "B", "year": 2023}),
1060-
Document(content="Doc 4", meta={"category": "B", "year": 2024}),
1057+
Document(content="Doc 1", meta={"category": "B", "year": 2023, "status": "draft"}),
1058+
Document(content="Doc 2", meta={"category": "B", "year": 2023, "status": "draft"}),
1059+
Document(content="Doc 3", meta={"category": "B", "year": 2023, "status": "published"}),
1060+
Document(content="Doc 4", meta={"category": "B", "year": 2024, "status": "draft"}),
10611061
]
10621062
document_store.write_documents(docs)
1063-
count = document_store.count_documents_by_filter( # type:ignore[attr-defined]
1063+
# The compound filter matches three documents with duplicated values, so the counts only come
1064+
# out right when the store both applies the filter and properly counts the values.
1065+
counts = document_store.count_unique_metadata_by_filter( # type:ignore[attr-defined]
10641066
filters={
10651067
"operator": "AND",
10661068
"conditions": [
10671069
{"field": "meta.category", "operator": "==", "value": "B"},
10681070
{"field": "meta.year", "operator": "==", "value": 2023},
10691071
],
1070-
}
1072+
},
1073+
metadata_fields=["status", "year"],
10711074
)
1072-
assert count == 1
1075+
assert counts == {"status": 2, "year": 1}
10731076

10741077

10751078
class GetMetadataFieldsInfoTest:

haystack/testing/document_store_async.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,15 @@ async def test_count_unique_metadata_by_filter_async_with_filter(document_store:
305305
async def test_count_unique_metadata_by_filter_async_with_multiple_filters(document_store: AsyncDocumentStore):
306306
"""Test counting unique metadata asynchronously with multiple filters."""
307307
docs = [
308-
Document(content="Doc 1", meta={"category": "A", "year": 2023}),
309-
Document(content="Doc 2", meta={"category": "A", "year": 2024}),
310-
Document(content="Doc 3", meta={"category": "B", "year": 2023}),
311-
Document(content="Doc 4", meta={"category": "B", "year": 2024}),
308+
Document(content="Doc 1", meta={"category": "B", "year": 2023, "status": "draft"}),
309+
Document(content="Doc 2", meta={"category": "B", "year": 2023, "status": "draft"}),
310+
Document(content="Doc 3", meta={"category": "B", "year": 2023, "status": "published"}),
311+
Document(content="Doc 4", meta={"category": "B", "year": 2024, "status": "draft"}),
312312
]
313313
await document_store.write_documents_async(docs)
314314

315+
# The compound filter matches three documents with duplicated values, so the counts only come
316+
# out right when the store both applies the filter and properly counts the values.
315317
counts = await document_store.count_unique_metadata_by_filter_async( # type:ignore[attr-defined]
316318
filters={
317319
"operator": "AND",
@@ -320,9 +322,9 @@ async def test_count_unique_metadata_by_filter_async_with_multiple_filters(docum
320322
{"field": "meta.year", "operator": "==", "value": 2023},
321323
],
322324
},
323-
metadata_fields=["category", "year"],
325+
metadata_fields=["status", "year"],
324326
)
325-
assert counts == {"category": 1, "year": 1}
327+
assert counts == {"status": 2, "year": 1}
326328

327329

328330
class DeleteByFilterAsyncTest:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed ``CountUniqueMetadataByFilterTest.test_count_unique_metadata_by_filter_with_multiple_filters``
5+
in the document store testing mixins: it called ``count_documents_by_filter`` instead of
6+
``count_unique_metadata_by_filter``. The test now exercises the intended method with a compound
7+
filter, matching its async counterpart.

0 commit comments

Comments
 (0)