-
Notifications
You must be signed in to change notification settings - Fork 220
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
to_dict() method converts integer field values to strings #36
Comments
That seems odd, any insight? @danielgtaylor |
For 64 bits int, spec requires it to be a string. There was a discussion on protobuf repo. But I do not quite understand the |
As far as I can see, the list implementation is equivalent to the single int64 type. It just converts all ints in the list to a string. Or is something else unclear about it? |
Oh that's for |
One thing I know we found confusing when looking into betterproto is that to_dict converts everything to the JSON representation, but that isn't really clearly documented. It makes sense with how to_json just json.dumps the output of to_dict, since without this conversion you'd have no way to ensure it matches the spec, but it's confusing when you're expected to_dict to return pythonic values like Maybe adding a separate |
That makes a lot of sense! I'm not entirely sure what the use-case is of depending on how users use to_dict, it could either be useful to convert everything to low-level values, or actually keep it pythonic.
|
@boukeversteegh One use case is to convert protobuf messages into domain objects with an object mapper. Most object mappers take dictionaries as arguments. |
Any updates for this? Currently on 2.0.0b2. My particular use case imports YAML, validates each property based on the dataclass field types, does some processing based on the field name/type, and passes the output of |
Would also +1 this issue. There's a related issue on how integers should be parsed as keys for map types in |
I know it was mentioned that the spec calls this out, but that either isn't true or was changed. The spec clear says that protobuf int64 values should be int/long in Python.
|
This has been fixed by adding to_pydict which will have the expected behaviour |
When using the to_dict method of a message, integer fields are converted to strings. This can be see on this line in the source code.
Why are integers converted to strings, while all other types are left as is? Is this a bug that i can open a PR for, or it deliberate? Any help is much appreciated as this seems like a bit odd behaviour
The text was updated successfully, but these errors were encountered: