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

no deserializer for Union[Literal[...], str] and payload of type str #47

Open
NiklasRosenstein opened this issue Jun 2, 2023 · 0 comments · May be fixed by #69
Open

no deserializer for Union[Literal[...], str] and payload of type str #47

NiklasRosenstein opened this issue Jun 2, 2023 · 0 comments · May be fixed by #69
Assignees
Labels
bug Something isn't working

Comments

@NiklasRosenstein
Copy link
Owner

from typing import Literal
from databind.json import load

MyType = Literal["Current", "FromEnvVar"] | str
assert load("hello", MyType) == "hello"

Expected behavior:

The value is deserialized as str would and returned as is.

Actual behavior:

> python test.py
Traceback (most recent call last):
  File "/home/coder/git/scm/test.py", line 7, in <module>
    assert load("hello", MyType) == "hello"
  File "/home/coder/git/scm/.venvs/3.10/lib/python3.10/site-packages/databind/json/__init__.py", line 67, in load
    return get_object_mapper().deserialize(value, type_, filename, settings)
  File "/home/coder/git/scm/.venvs/3.10/lib/python3.10/site-packages/databind/core/mapper.py", line 104, in deserialize
    self.convert(Direction.DESERIALIZE, value, datatype, Location(filename, None, None), settings),
  File "/home/coder/git/scm/.venvs/3.10/lib/python3.10/site-packages/databind/core/mapper.py", line 76, in convert
    return context.convert()
  File "/home/coder/git/scm/.venvs/3.10/lib/python3.10/site-packages/databind/core/context.py", line 123, in convert
    return self.convert_func(self)
  File "/home/coder/git/scm/.venvs/3.10/lib/python3.10/site-packages/databind/core/converter.py", line 86, in convert
    raise errors[0][1]
  File "/home/coder/git/scm/.venvs/3.10/lib/python3.10/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File "/home/coder/git/scm/.venvs/3.10/lib/python3.10/site-packages/databind/core/converter.py", line 87, in convert
    raise NoMatchingConverter(self, ctx, errors)
databind.core.converter.NoMatchingConverter: no deserializer for `TypeHint(typing.Union[typing.Literal['Current', 'FromEnvVar'], str])` and payload of type `str`

Trace:
    $: TypeHint(typing.Union[typing.Literal['Current', 'FromEnvVar'], str])
@NiklasRosenstein NiklasRosenstein added the bug Something isn't working label Jun 2, 2023
@NiklasRosenstein NiklasRosenstein self-assigned this Jun 2, 2023
rhaps0dy added a commit to rhaps0dy/python-databind that referenced this issue May 10, 2024
@rhaps0dy rhaps0dy linked a pull request May 10, 2024 that will close this issue
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