Skip to content

Validation bug: DocList and DocVec are not coerced to each other #1545

Description

@JohannesMessner

In the spirit of pydantic, a model (document) field that is annotated with a certain type should only ever hold data that is actually of that type.
To achieve that, incoming data of a different type should be coerced to the target type.

This does not happen between DocList and DocVec:

from docarray import BaseDoc, DocList, DocVec
from docarray.documents import ImageDoc


class Doc(BaseDoc):
    docs: DocList[ImageDoc]

d = Doc(docs=DocVec[ImageDoc]([ImageDoc()]))
# below should give <DocList[ImageDoc] (length=1)> but give <DocVec[ImageDoc] (length=1)>
print(d.docs)


class OtherDoc(BaseDoc):
    docs: DocVec[ImageDoc]

d = Doc(docs=DocList[ImageDoc]([ImageDoc()]))
# below should give <DocVec[ImageDoc] (length=1)> but give <DocList[ImageDoc] (length=1)>
print(d.docs)

Metadata

Metadata

Assignees

Labels

good-first-issueSuitable as your first contribution to DocArray!type/bugSomething isn't working

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions