Skip to content

Oneof behaviour not according to protobuf Language Guide #172

@benedikt-bartscher

Description

@benedikt-bartscher

https://protobuf.dev/programming-guides/proto3/#oneof

Oneof fields are like optional fields except all the fields in a oneof share memory, and at most one field can be set at the same time. Setting any member of the oneof automatically clears all the other members. You can check which value in a oneof is set (if any) using a special case() or WhichOneof() method, depending on your chosen language.

Note that if multiple values are set, the last set value as determined by the order in the proto will overwrite all previous ones.

this currently passes:

def test_multiple_oneof() -> None:
    msg = OneofTest(
        field_one=1,
        field_two=2,
    )
    assert msg.field_one == 1
    assert msg.field_two == 2

in the previous version (python-betterproto) it raised an AttributeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions