Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: fix create pure python class iteratively
Signed-off-by: Joan Martinez <[email protected]>
  • Loading branch information
JoanFM committed Feb 15, 2024
commit 7fcd9e7f0b3817eedb46d1cab0f2e69a885a13a9
3 changes: 2 additions & 1 deletion docarray/utils/create_dynamic_doc_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class MyDoc(BaseDoc):
try:
if safe_issubclass(field, DocList):
t: Any = field.doc_type
fields[field_name] = (List[t], field_info)
t_aux = create_pure_python_type_model(t)
fields[field_name] = (List[t_aux], field_info)
else:
fields[field_name] = (field, field_info)
except TypeError:
Expand Down
30 changes: 30 additions & 0 deletions tests/units/util/test_create_dynamic_code_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,33 @@ class CustomDoc(BaseDoc):
new_custom_doc_model.schema().get('description')
== 'Here I have the description of the class'
)


def test_dynamic_class_creation_multiple_doclist_nested():
from docarray import BaseDoc, DocList

class MyTextDoc(BaseDoc):
text: str

class QuoteFile(BaseDoc):
texts: DocList[MyTextDoc]

class SearchResult(BaseDoc):
results: DocList[QuoteFile] = None

models_created_by_name = {}
SearchResult_aux = create_pure_python_type_model(SearchResult)
_ = create_base_doc_from_schema(
SearchResult_aux.schema(), 'SearchResult', models_created_by_name
)
QuoteFile_reconstructed_in_gateway_from_Search_results = models_created_by_name[
'QuoteFile'
]
textlist = DocList[models_created_by_name['MyTextDoc']](
[models_created_by_name['MyTextDoc'](id='11', text='hey')]
)

reconstructed_in_gateway_from_Search_results = (
QuoteFile_reconstructed_in_gateway_from_Search_results(id='0', texts=textlist)
)
assert reconstructed_in_gateway_from_Search_results.texts[0].text == 'hey'