danielgtaylor / python-betterproto

Clean, modern, Python 3.6+ code generator & library for Protobuf 3 and async gRPC
MIT License
1.54k stars 216 forks source link

`Struct().from_dict(...)` has no effect #549

Closed woodruffw closed 10 months ago

woodruffw commented 10 months ago

Summary

protobuf.Struct appears to not load correctly with from_dict(...), which also affects from_json(...)

Reproduction Steps

I originally saw this with a more complex message, however I've minified it down to a single API call.

Using betterproto==2.0.0b6:

>>> import betterproto.lib.google.protobuf as protobuf
>>> protobuf.Struct().from_dict({"a": "b"})

Expected Results

I expect a Struct instance populated from the dictionary:

Struct(a="b")

Actual Results

I receive an empty Struct instance:

Struct()

System Information

libprotoc 25.1
Python 3.12.0
Name: betterproto
Version: 2.0.0b6
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: danielgtaylor@gmail.com
License: MIT
Location: /Users/william/devel/attestation/python/env/lib/python3.12/site-packages
Requires: grpclib, python-dateutil
Required-by: in-toto-attestation

Checklist

Gobot1234 commented 10 months ago

Duplicate of #332

woodruffw commented 10 months ago

Correct me if I'm wrong, but I don't believe these are duplicates: the linked issue says that the types aren't supported, while they do appear supported but have buggy behavior in the dictionary/JSON conversion cases.

woodruffw commented 10 months ago

The follow-up comment on the linked issue is also about a codegen miscompilation, which is not the observed behavior here.

Gobot1234 commented 10 months ago

We need to have special behaviour for the classes for which there is currently none, this is something else that requires special behaviour, the follow up comment doesn't necessarily mean that it's the same problem as the original issue

woodruffw commented 10 months ago

Okay, thanks for clarifying!