Skip to content

Commit c9d6ce9

Browse files
Joan FontanalsJoanFM
authored andcommitted
Merge branch 'master' into fix-6140
Signed-off-by: Joan Martinez <joan.fontanals.martinez@jina.ai>
2 parents 30b37f2 + 7fbbfcf commit c9d6ce9

4 files changed

Lines changed: 32 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ Jina is released on every Friday evening. The PyPi package and Docker Image will
655655
- [Release Note (`3.23.0`)](#release-note-3230)
656656
- [Release Note (`3.23.1`)](#release-note-3231)
657657
- [Release Note (`3.23.2`)](#release-note-3232)
658+
- [Release Note (`3.23.3`)](#release-note-3233)
658659

659660
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
660661

jina/serve/runtimes/helper.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def _parse_specific_params(parameters: Dict, executor_name: str):
100100
]
101101

102102

103-
def _create_aux_model_doc_list_to_list(model, cached_models = None):
104-
cached_models = cached_models or set()
103+
def _create_aux_model_doc_list_to_list(model, cached_models=None):
104+
cached_models = cached_models or {}
105105
fields: Dict[str, Any] = {}
106106
for field_name, field in model.__annotations__.items():
107107
if field_name not in model.__fields__:
@@ -111,11 +111,10 @@ def _create_aux_model_doc_list_to_list(model, cached_models = None):
111111
if issubclass(field, DocList):
112112
t: Any = field.doc_type
113113
if t.__name__ in cached_models:
114-
fields[field_name] = (List[t], field_info)
114+
fields[field_name] = (List[cached_models[t.__name__]], field_info)
115115
else:
116-
t_aux = _create_aux_model_doc_list_to_list(t)
116+
t_aux = _create_aux_model_doc_list_to_list(t, cached_models)
117117
fields[field_name] = (List[t_aux], field_info)
118-
cached_models.add(t.__name__)
119118
else:
120119
fields[field_name] = (field, field_info)
121120
except TypeError:
@@ -125,7 +124,7 @@ def _create_aux_model_doc_list_to_list(model, cached_models = None):
125124
__base__=model,
126125
__validators__=model.__validators__,
127126
**fields)
128-
cached_models.add(new_model.__name__)
127+
cached_models[model.__name__] = new_model
129128

130129
return new_model
131130

jina/serve/runtimes/worker/request_handling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ async def endpoint_discovery(self, empty, context) -> jina_pb2.EndpointsProto:
10021002
endpoints_proto.write_endpoints.extend(list(self._executor.write_endpoints))
10031003
schemas = self._executor._get_endpoint_models_dict()
10041004
if docarray_v2:
1005-
cached_aux_models = set()
1005+
cached_aux_models = {}
10061006
from docarray.documents.legacy import LegacyDocument
10071007

10081008
from jina.serve.runtimes.helper import _create_aux_model_doc_list_to_list

tests/unit/serve/runtimes/test_helper.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,28 @@ class SearchResult(BaseDoc):
382382
reconstructed_in_gateway_from_Search_results = QuoteFile_reconstructed_in_gateway_from_Search_results(
383383
texts=textlist)
384384
assert reconstructed_in_gateway_from_Search_results.texts[0].text == 'hey'
385+
386+
387+
@pytest.mark.skipif(not docarray_v2, reason='Test only working with docarray v2')
388+
def test_create_aux_model_with_multiple_doclists_of_same_type():
389+
from docarray import DocList, BaseDoc
390+
from jina.serve.runtimes.helper import _create_aux_model_doc_list_to_list
391+
392+
class MyTextDoc(BaseDoc):
393+
text: str
394+
395+
class QuoteFile(BaseDoc):
396+
texts: DocList[MyTextDoc]
397+
398+
class QuoteFileType(BaseDoc):
399+
"""
400+
QuoteFileType class.
401+
"""
402+
id: str = None # same as name, compatibility reasons for a generic, shared `id` field
403+
name: str = None
404+
total_count: int = None
405+
docs: DocList[QuoteFile] = None
406+
chunks: DocList[QuoteFile] = None
407+
408+
new_model = _create_aux_model_doc_list_to_list(QuoteFileType)
409+
new_model.schema()

0 commit comments

Comments
 (0)