Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Custom field serialzer in flattened field bug #453

Open
AustinScola opened this issue Dec 15, 2023 · 0 comments
Open

Custom field serialzer in flattened field bug #453

AustinScola opened this issue Dec 15, 2023 · 0 comments
Labels
bug Bug report or fix

Comments

@AustinScola
Copy link

It appears that a custom field serializer inside of a flattened field fails to serialzie:

Example:

from serde import field, serialize, to_dict

@serialize
class Child:
    value: int = field(serializer=str)

@serialize
class Parent:
    child: Child = field(flatten=True)

parent = Parent(child=Child(value=3))
print(to_dict(parent))

Stacktrace:

Traceback (most recent call last):
  File "/private/tmp/foo.py", line 12, in <module>
    print(to_dict(parent))
          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/serde/se.py", line 450, in to_dict
    return to_obj(  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/serde/se.py", line 378, in to_obj
    raise SerdeError(e) from None
serde.compat.SerdeError: name 'value_serializer' is not defined
@yukinarit yukinarit added the bug Bug report or fix label Jan 7, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Bug report or fix
Projects
None yet
Development

No branches or pull requests

2 participants