Skip to content

Bug: initializing Document with dataclass and additional kwargs #447

@JohannesMessner

Description

@JohannesMessner

Description

Initializing a Document with a dataclass and other kwargs ignores the dataclass, and only the top level kwargs get set.

How to reproduce

from docarray import DocumentArray, Document, dataclass
from docarray.typing import Text

@dataclass
class MyDoc:
    chunk_text: Text

d = Document(MyDoc(chunk_text='chunk level text'), text='top level text')
print(d.is_multimodal)  # should be True, but is False
print(d.text)  # should print 'top level text'
print(d.chunk_text.text)  # should print 'chunk level text', but fails

Possible fix

In the constructor the dataclass information gets correctly put into self._data in this line, but than self._data get overridden here.
We probably need some logic to merge the two.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions