Skip to content

Commit

Permalink
Merge branch 'master' into fix-6140
Browse files Browse the repository at this point in the history
Signed-off-by: Joan Martinez <[email protected]>
  • Loading branch information
JoanFM committed Feb 19, 2024
2 parents 30b37f2 + 7fbbfcf commit 4eef9ed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

Expand Down
5 changes: 2 additions & 3 deletions jina/serve/runtimes/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ 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)

Check warning on line 114 in jina/serve/runtimes/helper.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/helper.py#L113-L114

Added lines #L113 - L114 were not covered by tests
else:
t_aux = _create_aux_model_doc_list_to_list(t)
t_aux = _create_aux_model_doc_list_to_list(t, cached_models)
fields[field_name] = (List[t_aux], field_info)

Check warning on line 117 in jina/serve/runtimes/helper.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/helper.py#L116-L117

Added lines #L116 - L117 were not covered by tests
cached_models.add(t.__name__)
else:
fields[field_name] = (field, field_info)
except TypeError:
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/serve/runtimes/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 4eef9ed

Please sign in to comment.