Skip to content

Commit 69fda3b

Browse files
fix: SupaBase override test_get_metadata_field_unique_values_distinct_types (#3852)
1 parent 359859d commit 69fda3b

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

integrations/supabase/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ classifiers = [
2323
"Programming Language :: Python :: Implementation :: CPython",
2424
"Programming Language :: Python :: Implementation :: PyPy",
2525
]
26-
dependencies = ["haystack-ai>=2.26.1", "pgvector-haystack>=6.3.0", "supabase>=2.23.0"]
26+
dependencies = ["haystack-ai>=2.26.1", "pgvector-haystack>=6.6.0", "supabase>=2.23.0"]
2727

2828
[project.urls]
2929
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/supabase#readme"

integrations/supabase/tests/test_document_store.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,41 @@ def test_write_documents(self, document_store: SupabasePgvectorDocumentStore):
4545
with pytest.raises(DuplicateDocumentError):
4646
document_store.write_documents(docs, DuplicatePolicy.FAIL)
4747

48+
def test_get_metadata_field_unique_values_distinct_types(self, document_store: SupabasePgvectorDocumentStore):
49+
"""
50+
Override: the base mixin test stores int, float, str and bool under the *same* metadata field
51+
name and expects all four back as distinct values. This store's ``meta`` column is JSONB, and
52+
PostgreSQL's JSONB equality treats a whole-number float (e.g. 1.0) and a numerically equal int
53+
(1) as the same value, so ``SELECT DISTINCT meta->'field'`` collapses them regardless of which
54+
other values share that field.
55+
56+
This adapts the same intent - int, float, str and bool must come back as distinct, unmangled
57+
types via get_metadata_field_unique_values() - using one field per type instead of one shared
58+
field, which is what this store can actually support.
59+
60+
The float value is a non-whole number (1.5, not 1.0): a whole-number float would still collapse
61+
with an int under PostgreSQL's JSONB numeric equality even in its own field, so a fractional
62+
value is used to sidestep that ambiguity entirely.
63+
"""
64+
docs = [
65+
Document(content="Doc 1", meta={"priority_int": 1}),
66+
Document(content="Doc 2", meta={"priority_str": "1"}),
67+
Document(content="Doc 3", meta={"priority_float": 1.5}),
68+
Document(content="Doc 4", meta={"priority_bool": True}),
69+
]
70+
document_store.write_documents(docs)
71+
72+
int_values, int_count = document_store.get_metadata_field_unique_values(metadata_field="priority_int")
73+
str_values, str_count = document_store.get_metadata_field_unique_values(metadata_field="priority_str")
74+
float_values, float_count = document_store.get_metadata_field_unique_values(metadata_field="priority_float")
75+
bool_values, bool_count = document_store.get_metadata_field_unique_values(metadata_field="priority_bool")
76+
77+
assert (int_count, str_count, float_count, bool_count) == (1, 1, 1, 1)
78+
assert int_values == [1] and type(int_values[0]) is int
79+
assert str_values == ["1"] and type(str_values[0]) is str
80+
assert float_values == [1.5] and type(float_values[0]) is float
81+
assert bool_values == [True] and type(bool_values[0]) is bool
82+
4883
def test_write_blob(self, document_store: SupabasePgvectorDocumentStore):
4984
bytestream = ByteStream(b"test", meta={"meta_key": "meta_value"}, mime_type="mime_type")
5085
docs = [Document(id="1", blob=bytestream)]

uv.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ exclude-newer = "24 hours"
77
[exclude-newer-package]
88
haystack-ai = false
99
tavily-haystack = false
10+
pgvector-haystack = false

0 commit comments

Comments
 (0)