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

Unions break depending on order #271

Closed
kevinheavey opened this issue Dec 6, 2021 · 1 comment · Fixed by #272
Closed

Unions break depending on order #271

kevinheavey opened this issue Dec 6, 2021 · 1 comment · Fixed by #272
Milestone

Comments

@kevinheavey
Copy link
Contributor

I get an error when deserialising Union[Literal, MyClass] but not when deserialising Union[MyClass, Literal].
It seems this error started some time after v0.15.7.

Example:

from typing import Union, Literal
from dataclasses import dataclass
from apischema import deserialize


@dataclass
class Bar:
    baz: int


deserialize(Union[Literal["foo"], Bar], {"baz": 1})  # this fails
deserialize(Union[Bar, Literal["foo"]], {"baz": 1})  # this works

Here's the traceback for the the call that fails:

Traceback (most recent call last):
  File "/home/kheavey/anchorpy/throwaway.py", line 11, in <module>
    deserialize(Union[Literal["foo"], Bar], {"baz": 1})
  File "/home/kheavey/anchorpy/.venv/lib/python3.9/site-packages/apischema/utils.py", line 424, in wrapper
    return wrapped(*args, **kwargs)
  File "/home/kheavey/anchorpy/.venv/lib/python3.9/site-packages/apischema/deserialization/__init__.py", line 912, in deserialize
    return deserialization_method(
  File "/home/kheavey/anchorpy/.venv/lib/python3.9/site-packages/apischema/deserialization/__init__.py", line 698, in method
    return deserialize_alt(data)
  File "/home/kheavey/anchorpy/.venv/lib/python3.9/site-packages/apischema/deserialization/__init__.py", line 271, in method
    return value_map[data]
TypeError: unhashable type: 'dict'

Here's what value_map and data look like:

(Pdb) value_map
{'foo': 'foo'}
(Pdb) data
{'baz': 1}
@wyfo wyfo linked a pull request Dec 6, 2021 that will close this issue
@wyfo wyfo modified the milestones: v0.16.2, v0.16.3 Dec 6, 2021
@wyfo
Copy link
Owner

wyfo commented Dec 6, 2021

Fixed in v0.16.3

@wyfo wyfo closed this as completed Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants