Skip to content

Commit 2be2796

Browse files
committed
fix: fix create pure python class iteratively
Signed-off-by: Joan Martinez <[email protected]>
1 parent aa15b9e commit 2be2796

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

docarray/utils/create_dynamic_doc_class.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class MyDoc(BaseDoc):
6767
try:
6868
if safe_issubclass(field, DocList):
6969
t: Any = field.doc_type
70-
fields[field_name] = (List[t], field_info)
70+
t_aux = create_pure_python_type_model(t)
71+
fields[field_name] = (List[t_aux], field_info)
7172
else:
7273
fields[field_name] = (field, field_info)
7374
except TypeError:

tests/units/util/test_create_dynamic_code_class.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,34 @@ class CustomDoc(BaseDoc):
278278
'Example here'
279279
]
280280
assert (
281-
new_custom_doc_model.schema().get('properties')['a']['another_extra']
282-
== 'I am another extra'
281+
new_custom_doc_model.schema().get('properties')['a']['another_extra']
282+
== 'I am another extra'
283283
)
284284
assert (
285-
new_custom_doc_model.schema().get('description')
286-
== 'Here I have the description of the class'
285+
new_custom_doc_model.schema().get('description')
286+
== 'Here I have the description of the class'
287287
)
288+
289+
290+
def test_dynamic_class_creation_multiple_doclist_nested():
291+
from docarray import BaseDoc, DocList
292+
293+
class MyTextDoc(BaseDoc):
294+
text: str
295+
296+
class QuoteFile(BaseDoc):
297+
texts: DocList[MyTextDoc]
298+
299+
class SearchResult(BaseDoc):
300+
results: DocList[QuoteFile] = None
301+
302+
textlist = DocList[MyTextDoc]([MyTextDoc(text='hey')])
303+
models_created_by_name = {}
304+
SearchResult_aux = create_pure_python_type_model(SearchResult)
305+
_ = create_base_doc_from_schema(SearchResult_aux.schema(), 'SearchResult',
306+
models_created_by_name)
307+
QuoteFile_reconstructed_in_gateway_from_Search_results = models_created_by_name['QuoteFile']
308+
309+
reconstructed_in_gateway_from_Search_results = QuoteFile_reconstructed_in_gateway_from_Search_results(
310+
texts=textlist)
311+
assert reconstructed_in_gateway_from_Search_results.texts[0].text == 'hey'

0 commit comments

Comments
 (0)