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

ValueRule.to_python fails with empty Value field #351

Open
dizcology opened this issue Apr 12, 2023 · 0 comments
Open

ValueRule.to_python fails with empty Value field #351

dizcology opened this issue Apr 12, 2023 · 0 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@dizcology
Copy link

dizcology commented Apr 12, 2023

An example:

from google.protobuf import struct_pb2

import proto

class Model(proto.Message):
    metadata: struct_pb2.Value = proto.Field(
        proto.MESSAGE,
        number=6,
        message=struct_pb2.Value,
    )

empty_value = struct_pb2.Value()
m = Model(metadata=empty_value)

print('metadata' in m)  # not absent
print(m._pb.metadata.WhichOneof('kind'))  # None Value kind
print(m._pb.metadata == empty_value)  # The empty Value can be accessed through `_pb`
m.metadata  # But this fails with: ValueError: Unexpected kind: None

The error is raised at

raise ValueError("Unexpected kind: %s" % kind) # pragma: NO COVER

In the situation above, absent is False, while kind is None.

My expectation is that since protobuf allows the construction of empty Values, proto-plus should too. However, it is unclear to me what should be the return value of to_python in this case.

@dizcology dizcology added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

1 participant