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

Message with oneof called method .to_pydict/.from_pydict fails #610

Open
3 tasks done
RF-Tar-Railt opened this issue Sep 6, 2024 · 0 comments · May be fixed by #609
Open
3 tasks done

Message with oneof called method .to_pydict/.from_pydict fails #610

RF-Tar-Railt opened this issue Sep 6, 2024 · 0 comments · May be fixed by #609
Labels
bug Something isn't working investigation needed

Comments

@RF-Tar-Railt
Copy link

RF-Tar-Railt commented Sep 6, 2024

Summary

Serializing a message with oneof fails by to_pydict or from_pydict.

Reproduction Steps

Define a message and compile:

message Foo {
  oneof group1 {
    int32 bar = 1;
    int32 baz = 2;
  }
}

then called Foo(bar=1).to_pydict or Foo().from_pydict({"bar": 1})

Expected Results

The method called success like to_dict and from_dict

Actual Results

There will raise AttributeError: 'group1' is set to 'xxxx', not 'baz' / 'group1' is set to None, not 'bar':

Traceback (most recent call last):
  File "D:\Projects\adapter-kritor\exam.py", line 22, in <module>
    res = foo1.to_pydict()
  File "D:\Projects\adapter-kritor\.venv\lib\site-packages\betterproto\__init__.py", line 1717, in to_pydict
    value = getattr(self, field_name)
  File "D:\Projects\adapter-kritor\.venv\lib\site-packages\betterproto\__init__.py", line 836, in __getattribute__
    raise AttributeError(
AttributeError: 'group1' is set to 'bar', not 'baz'

System Information

libprotoc 27.2
Python 3.9.13
2.0.0b7

Checklist

  • I have searched the issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have verified this issue occurs on the latest prelease of betterproto which can be installed using pip install -U --pre betterproto, if possible.
@RF-Tar-Railt RF-Tar-Railt added bug Something isn't working investigation needed labels Sep 6, 2024
@RF-Tar-Railt RF-Tar-Railt linked a pull request Sep 6, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigation needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant