You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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 throughfrom_dict
will work differently than throughschema().load(...)
.Code snippet that reproduces the issue
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
The text was updated successfully, but these errors were encountered: