wyfo / apischema

JSON (de)serialization, GraphQL and JSON schema generation using Python typing.

Home Page:https://wyfo.github.io/apischema/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deserialization failure when a deserialization occurs before adding a deserializer

pchanial opened this issue · comments

Performing deserializations prevents later addition of deserializers.
For correctness. It does not correspond to a use case, since I encountered this problem while I was debugging.
It is most likely due to the internal caching.

import pytest
from apischema import ValidationError, deserialize, deserializer
from apischema.conversions import Conversion, catch_value_error

class Foo(int):
    pass

deserialize(Foo, 1)   # <--- by removing this line, no ValidationError will be raised below

deserializer(Conversion(catch_value_error(Foo), source=str, target=Foo))
with pytest.raises(ValidationError):
    deserialize(Foo, '1')

Thank you for reporting this bug. Normally, apischema cache should be reset each time a global operation, like deserializer is performed. It will be fixed in next patch.