Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python deserialization fails for union types #1164

Closed
Thoralf-M opened this issue Sep 7, 2023 · 3 comments · Fixed by #1335
Closed

Python deserialization fails for union types #1164

Thoralf-M opened this issue Sep 7, 2023 · 3 comments · Fixed by #1335
Assignees
Labels
b-python Bindings - Python bug Bug m-all Module - All t-refactor Task - Refactor

Comments

@Thoralf-M
Copy link
Member

Thoralf-M commented Sep 7, 2023

Description

Deserialization fails for union types if the data is not always matching the first type.
For example address: Ed25519Address | AliasAddress | NFTAddress only works if the type matches the Ed25519Address variant, for AliasAddress or NFTAddress an error is returned.

Didn't found a solution yet, but maybe can be done with something similar to this

    # https://github.com/lidatong/dataclasses-json/issues/303
    address: Ed25519Address | AliasAddress | NFTAddress = field(
        metadata=config(
            decoder=lambda d: 
            match d["type"]:
                    case AddressType.Ed25519:
                        Ed25519Address.from_dict(d)
                    case ...

If not probably a custom _from_dict_custom(), similar to

def _to_dict_custom(config: Dict[str, any]) -> Dict[str, any]:
can be used

https://github.com/lidatong/dataclasses-json/pull/478 might help

Motivation

Make deserialization work correct

Are you planning to do it yourself in a pull request?

No.

@Thoralf-M Thoralf-M added the b-python Bindings - Python label Sep 7, 2023
@Thoralf-M Thoralf-M added this to the v2.0.0 milestone Sep 7, 2023
@github-project-automation github-project-automation bot moved this to Product Backlog in iota-sdk Sep 7, 2023
@thibault-martinez
Copy link
Member

Only happening in 2.0?

@Thoralf-M
Copy link
Member Author

Yes, most probably introduced in 80a5667

@thibault-martinez thibault-martinez added bug Bug m-all Module - All t-refactor Task - Refactor labels Sep 13, 2023
@thibault-martinez thibault-martinez moved this from Product Backlog to Sprint Backlog in iota-sdk Sep 19, 2023
@Thoralf-M Thoralf-M moved this from Sprint Backlog to In Progress in iota-sdk Sep 25, 2023
@Thoralf-M Thoralf-M moved this from In Progress to In Review in iota-sdk Sep 27, 2023
@Thoralf-M Thoralf-M linked a pull request Sep 27, 2023 that will close this issue
@thibault-martinez
Copy link
Member

Closed by #1335

@github-project-automation github-project-automation bot moved this from In Review to Done in iota-sdk Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b-python Bindings - Python bug Bug m-all Module - All t-refactor Task - Refactor
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants