Skip to content

Dump converts int or bool to float #2816

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

Open
Oriel-Barroso opened this issue Mar 31, 2025 · 1 comment
Open

Dump converts int or bool to float #2816

Oriel-Barroso opened this issue Mar 31, 2025 · 1 comment

Comments

@Oriel-Barroso
Copy link

I have an schema:

class ExampleSchema(Schema):
    name: str
    value: int | float | bool

When I pass an integer or boolean value, marshmallow converts it into a float. Is there any clean way to correct this?

@deckar01
Copy link
Member

deckar01 commented Apr 3, 2025

Duplicate of #270.

See https://github.com/Bachmann1234/marshmallow-polyfield

Your use case is closer to Union field, but it wouldn’t work because all the types are compatible.

https://github.com/adamboche/python-marshmallow-union

I suspect this “polynumber” use case is common enough to justify a utility that maps the type or minimizes value change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants