Skip to content

Conversation

@maxwelljin
Copy link
Contributor

@maxwelljin maxwelljin commented Jun 16, 2023

This bug is caused by the deserialization process. The deserialization function currently only checks the schema of the class, without specific information about the particular document type in the field of union type. To resolve this issue, we may need to modify the data storage. After discussing with Joan, we could temporarily remove support for the union type and add this info the document. Additionally, we provide users with a more informative error message.

Signed-off-by: maxwelljin2 <gejin@berkeley.edu>
@maxwelljin maxwelljin marked this pull request as ready for review June 16, 2023 04:09
```

!!! note
Currently, union type hints are not supported for serialization to protobuf formats.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any union type? or Union types of regular types are? Can u add tests for the exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add more tests. It should be any union type as union type doesn't have the from_protobuf method

Signed-off-by: maxwelljin2 <gejin@berkeley.edu>
@maxwelljin
Copy link
Contributor Author

Currently, the serialization for union type is only supported through from_json and to_json. This new commit adds tests to this bug.

Copy link
Member

@JoanFM JoanFM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not answered what happens with Union of basic types


!!! note
Currently, union type hints are not supported for serialization to protobuf formats.
Serialization to protobuf formats is not supported for union type hints. Please consider using JSON serialization as an alternative.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid the consideration, just inform


from docarray.documents import TextDoc

class CustomDoc(BaseDoc):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about Union[int, float] or Union[int, str]

Copy link
Contributor Author

@maxwelljin maxwelljin Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the testing, the Union with basic types should work in all serialization methods. Only the Union with document types will cause those issues.

Signed-off-by: maxwelljin2 <gejin@berkeley.edu>
Signed-off-by: maxwelljin2 <gejin@berkeley.edu>
Signed-off-by: Joan Fontanals <jfontanalsmartinez@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Bug serializing and deserializing with nested Union of BaseDocs

2 participants