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

[BUG] Generated schema doesn't take into account custom decoder #460

Closed
deansg opened this issue Aug 4, 2023 · 0 comments · Fixed by #462
Closed

[BUG] Generated schema doesn't take into account custom decoder #460

deansg opened this issue Aug 4, 2023 · 0 comments · Fixed by #462
Labels
bug Something isn't working

Comments

@deansg
Copy link
Contributor

deansg commented Aug 4, 2023

Description

If a custom decoder is specified on a dataclass, the schema generated by the class' schema() method doesn't properly take it into account. This creates a situation where deserializing a dictionary through from_dict will work differently than through schema().load(...).

Code snippet that reproduces the issue

def split_str(data: str):
    return data.split(',')


@dataclass_json
@dataclass
class SomeClass:
    a: list[str] = field(
        default=None,
        metadata=config(
            decoder=split_str
        )
    )


def test_schemas():
    b = SomeClass.from_dict({'a': '1,2,3'})
    c = SomeClass.schema().load({'a': '1,2,3'})

In this example, variable b is deserialized correctly, while trying to deserialize using Someclass.schema().load(...) throws the following exception:

marshmallow.exceptions.ValidationError: {'a': ['Not a valid list.']}

Describe the results you expected

Full consistency between .schema().load(...) and .from_dict(), both will take the custom decoder into account.

Python version you are using

3.10.5

Environment description

dataclasses-json==0.5.14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant