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

SerdeError deserializing list of optional #329

Open
davetapley opened this issue Mar 23, 2023 · 3 comments
Open

SerdeError deserializing list of optional #329

davetapley opened this issue Mar 23, 2023 · 3 comments
Assignees
Labels
bug Bug report or fix

Comments

@davetapley
Copy link
Contributor

Seen on 0.9.7 but then updated and still present on 0.10.2 (#315 is amazing BTW 👏🏻 👏🏻 👏🏻 ):

from dataclasses import dataclass
from serde.json import to_json, from_json

@dataclass
class Foo():
    stuff: list[int | None]

foo = to_json(Foo([1, 2, None]))
from_json(Foo, foo)
Traceback (most recent call last):
  File "/home/dave/.pyenv/versions/ng/lib/python3.10/site-packages/serde/de.py", line 398, in from_obj
    return deserializable_to_obj(c)
  File "/home/dave/.pyenv/versions/ng/lib/python3.10/site-packages/serde/de.py", line 380, in deserializable_to_obj
    res = serde_scope.funcs[func_name](cls, maybe_generic=maybe_generic, data=o, reuse_instances=reuse_instances)
  File "<string>", line 11, in from_dict
  File "<string>", line 11, in <listcomp>
AttributeError: 'int' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dave/ng/pyserde_list_float_bug.py", line 9, in <module>
    from_json(Foo, foo)
  File "/home/dave/.pyenv/versions/ng/lib/python3.10/site-packages/serde/json.py", line 77, in from_json
    return from_dict(c, de.deserialize(s, **opts), reuse_instances=False)
  File "/home/dave/.pyenv/versions/ng/lib/python3.10/site-packages/serde/de.py", line 486, in from_dict
    return from_obj(cls, o, named=True, reuse_instances=reuse_instances)
  File "/home/dave/.pyenv/versions/ng/lib/python3.10/site-packages/serde/de.py", line 463, in from_obj
    raise SerdeError(e)
serde.compat.SerdeError: 'int' object has no attribute 'get'
@yukinarit yukinarit added the bug Bug report or fix label Mar 25, 2023
@yukinarit yukinarit self-assigned this Mar 26, 2023
@davetapley
Copy link
Contributor Author

@yukinarit do you need/want any help on this?

I'll need to implement a workaround soon as I have to ship something, but I'd rather make a PR here if you can point me in the right direction and we can get merged in next week or so 😁

@yukinarit
Copy link
Owner

@davetapley Sorry, I missed this. I will work on this next.

@yukinarit yukinarit moved this to Doing 🏃‍♂️ in pyserde's new roadmap Jun 14, 2023
@davetapley
Copy link
Contributor Author

@yukinarit FYI still present in v0.22.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report or fix
Projects
Status: Doing 🏃‍♂️
Development

No branches or pull requests

2 participants