Skip to content

Commit cf093f6

Browse files
Bugfix - Protobuf stored fields parsed as character strings (#972)
Signed-off-by: Finn Carroll <[email protected]>
1 parent dc94244 commit cf093f6

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

osbenchmark/worker_coordinator/proto_helpers/ProtoQueryHelper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ def build_vector_search_proto_request(params):
140140
source_config = common_pb2.SourceConfigParam(bool=fetch_source)
141141
timeout = params.get("request-timeout")
142142

143-
if body.get("stored_fields") is None or body.get("stored_fields") is STORED_FIELDS_NONE:
143+
stored_fields = body.get("stored_fields")
144+
if stored_fields is None or stored_fields == STORED_FIELDS_NONE:
144145
stored_fields = [STORED_FIELDS_NONE]
145-
else:
146-
stored_fields = body.get("stored_fields")
146+
elif not isinstance(stored_fields, list):
147+
raise Exception("Error parsing query params - Stored fields must be a list")
147148

148149
if isinstance(params.get("cache"), bool):
149150
cache = params.get("cache")

tests/worker_coordinator/proto_query_helper_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,41 @@ def test_build_vector_search_proto_defaults_with_optional_fields_empty(self):
177177
self.assertEqual(request.timeout, '')
178178
self.assertEqual(request.request_body.profile, False)
179179

180+
def test_build_vector_search_proto_stored_fields_non_list_parsing(self):
181+
params = {
182+
'body': {
183+
'query': {
184+
'knn': {
185+
'knn_field': {
186+
'vector': np.array([1.0], dtype=np.float32),
187+
'k': 100
188+
}
189+
}
190+
},
191+
'docvalue_fields': ['_id'],
192+
'stored_fields': "_none_",
193+
},
194+
'request-params': {},
195+
'index': 'index_required',
196+
'k': 100,
197+
}
198+
199+
request = ProtoQueryHelper.build_vector_search_proto_request(params)
200+
201+
self.assertEqual(request.stored_fields, ["_none_"])
202+
203+
params['body']['stored_fields'] = ['field1', 'field2']
204+
request = ProtoQueryHelper.build_vector_search_proto_request(params)
205+
206+
self.assertEqual(request.stored_fields, ['field1', 'field2'])
207+
208+
params['body']['stored_fields'] = 'field1'
209+
210+
with self.assertRaises(Exception) as context:
211+
ProtoQueryHelper.build_vector_search_proto_request(params)
212+
213+
self.assertIn('Stored fields must be a list', str(context.exception))
214+
180215
def test_build_vector_search_proto_string_or_bool(self):
181216
params = {
182217
'body': {

0 commit comments

Comments
 (0)