diff --git a/CHANGELOG.md b/CHANGELOG.md index 86bae749f32fb..11cd06fd04f8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -655,6 +655,7 @@ Jina is released on every Friday evening. The PyPi package and Docker Image will - [Release Note (`3.23.0`)](#release-note-3230) - [Release Note (`3.23.1`)](#release-note-3231) - [Release Note (`3.23.2`)](#release-note-3232) +- [Release Note (`3.23.3`)](#release-note-3233) diff --git a/jina/serve/runtimes/helper.py b/jina/serve/runtimes/helper.py index 5d3561bc6c397..0319f7c8a18d8 100644 --- a/jina/serve/runtimes/helper.py +++ b/jina/serve/runtimes/helper.py @@ -100,8 +100,8 @@ def _parse_specific_params(parameters: Dict, executor_name: str): ] - def _create_aux_model_doc_list_to_list(model, cached_models = None): - cached_models = cached_models or set() + def _create_aux_model_doc_list_to_list(model, cached_models=None): + cached_models = cached_models or {} fields: Dict[str, Any] = {} for field_name, field in model.__annotations__.items(): if field_name not in model.__fields__: @@ -111,11 +111,11 @@ def _create_aux_model_doc_list_to_list(model, cached_models = None): if issubclass(field, DocList): t: Any = field.doc_type if t.__name__ in cached_models: - fields[field_name] = (List[t], field_info) + fields[field_name] = (List[cached_models[t.__name__]], field_info) else: - t_aux = _create_aux_model_doc_list_to_list(t) + t_aux = _create_aux_model_doc_list_to_list(t, cached_models) + cached_models[t.__name__] = t_aux fields[field_name] = (List[t_aux], field_info) - cached_models.add(t.__name__) else: fields[field_name] = (field, field_info) except TypeError: @@ -125,7 +125,7 @@ def _create_aux_model_doc_list_to_list(model, cached_models = None): __base__=model, __validators__=model.__validators__, **fields) - cached_models.add(new_model.__name__) + cached_models[model.__name__] = new_model return new_model diff --git a/jina/serve/runtimes/worker/request_handling.py b/jina/serve/runtimes/worker/request_handling.py index 5e8b7109adf5e..6756eb0356ed8 100644 --- a/jina/serve/runtimes/worker/request_handling.py +++ b/jina/serve/runtimes/worker/request_handling.py @@ -1002,7 +1002,7 @@ async def endpoint_discovery(self, empty, context) -> jina_pb2.EndpointsProto: endpoints_proto.write_endpoints.extend(list(self._executor.write_endpoints)) schemas = self._executor._get_endpoint_models_dict() if docarray_v2: - cached_aux_models = set() + cached_aux_models = {} from docarray.documents.legacy import LegacyDocument from jina.serve.runtimes.helper import _create_aux_model_doc_list_to_list diff --git a/tests/unit/serve/runtimes/test_helper.py b/tests/unit/serve/runtimes/test_helper.py index 43abba91f2157..b16ac39dd18bf 100644 --- a/tests/unit/serve/runtimes/test_helper.py +++ b/tests/unit/serve/runtimes/test_helper.py @@ -382,3 +382,28 @@ class SearchResult(BaseDoc): reconstructed_in_gateway_from_Search_results = QuoteFile_reconstructed_in_gateway_from_Search_results( texts=textlist) assert reconstructed_in_gateway_from_Search_results.texts[0].text == 'hey' + + +@pytest.mark.skipif(not docarray_v2, reason='Test only working with docarray v2') +def test_create_aux_model_with_multiple_doclists_of_same_type(): + from docarray import DocList, BaseDoc + from jina.serve.runtimes.helper import _create_aux_model_doc_list_to_list + + class MyTextDoc(BaseDoc): + text: str + + class QuoteFile(BaseDoc): + texts: DocList[MyTextDoc] + + class QuoteFileType(BaseDoc): + """ + QuoteFileType class. + """ + id: str = None # same as name, compatibility reasons for a generic, shared `id` field + name: str = None + total_count: int = None + docs: DocList[QuoteFile] = None + chunks: DocList[QuoteFile] = None + + new_model = _create_aux_model_doc_list_to_list(QuoteFileType) + new_model.schema()