Skip to content

Error on accessing unset optional field #523

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

Closed
124C41p opened this issue Aug 31, 2023 · 1 comment · Fixed by #528
Closed

Error on accessing unset optional field #523

124C41p opened this issue Aug 31, 2023 · 1 comment · Fixed by #528

Comments

@124C41p
Copy link
Contributor

124C41p commented Aug 31, 2023

On main branch, the proto message

message Foo {
    optional int32 a = 1;
}

is compiled to

@dataclass(eq=False, repr=False)
class Foo(betterproto.Message):
    a: Optional[int] = betterproto.int32_field(1, optional=True, group="_a")

Now both Foo().a and Foo(a=None).a raises the same AttributeError: '_a' is set to None, not 'a' . This is probably unwanted behavior?

It seems to be fixed by removing the term group="_a" manually. Is there a reason to set the group in this case in the first place?

@124C41p
Copy link
Contributor Author

124C41p commented Sep 23, 2023

Related to #499

cetanu pushed a commit that referenced this issue Oct 16, 2023
cetanu pushed a commit that referenced this issue Oct 16, 2023
cetanu pushed a commit that referenced this issue Oct 16, 2023
Gobot1234 added a commit that referenced this issue Oct 16, 2023
cetanu pushed a commit that referenced this issue Oct 16, 2023
bbonenfant pushed a commit to pachyderm/python-betterproto that referenced this issue Jan 23, 2024
bbonenfant pushed a commit to pachyderm/python-betterproto that referenced this issue Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant