Skip to content

AnyDoc not working as expected #1570

@JoanFM

Description

@JoanFM

I believe this should work:

from docarray import DocList
from docarray.base_doc import AnyDoc, BaseDoc
from typing import Dict

class ProcessingTestDocConditions(BaseDoc):
    text: str
    tags: Dict[str, int]

input_da = DocList[ProcessingTestDocConditions](
    [ProcessingTestDocConditions(text='type1', tags={'type': 1}),
     ProcessingTestDocConditions(text='type2', tags={'type': 2})])

from docarray.base_doc import AnyDoc
aux = DocList[AnyDoc].from_protobuf(input_da.to_protobuf())
assert len(aux.id) == 2
Traceback (most recent call last):
  File "/home/joan/jina/docarray/docarray/array/doc_list/doc_list.py", line 296, in from_protobuf
    return super().from_protobuf(pb_msg)
  File "/home/joan/jina/docarray/docarray/array/doc_list/io.py", line 119, in from_protobuf
    return cls(cls.doc_type.from_protobuf(doc_proto) for doc_proto in pb_msg.docs)
  File "/home/joan/jina/docarray/docarray/array/doc_list/doc_list.py", line 128, in __init__
    super().__init__(docs)
  File "/home/joan/jina/docarray/docarray/array/doc_list/doc_list.py", line 155, in _validate_docs
    for doc in docs:
  File "/home/joan/jina/docarray/docarray/array/doc_list/io.py", line 119, in <genexpr>
    return cls(cls.doc_type.from_protobuf(doc_proto) for doc_proto in pb_msg.docs)
  File "/home/joan/jina/docarray/docarray/base_doc/mixins/io.py", line 243, in from_protobuf
    pb_msg.data[field_name], field_name
  File "/home/joan/jina/docarray/docarray/base_doc/mixins/io.py", line 320, in _get_content_from_node_proto
    field_type = cls.__fields__[field_name].type_ if field_name else None
KeyError: 'tags'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions