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

Remove error when no fields are set in oneof #612

Merged
merged 1 commit into from
Oct 5, 2024

Conversation

AdrienVannson
Copy link
Contributor

@AdrienVannson AdrienVannson commented Sep 9, 2024

Summary

Fix #604

Methods such as parse are often called on a new object: value = cls().parse(value). However, is the message contains oneof fields, this used to make the validator _validate_field_groups fail when using pydantic.

I removed the check that at least one value of the oneof is defined. This is coherent with gRPC's documentation: "If you have a message with many fields and where at most one field will be set at the same time, you can enforce this behavior and save memory by using the oneof feature." and "You can check which value in a oneof is set (if any) using a special case() or WhichOneof() method"

Checklist

  • If code changes were made then they have been tested.
  • This PR fixes an issue.

@AdrienVannson
Copy link
Contributor Author

AdrienVannson commented Sep 19, 2024

I forget to mention: this problem makes some of the tests from test_inputs.py fail. The problem only appears when plugin_output_package is manually set to "tests.output_betterproto_pydantic", which is not the case by default. Once this problem (and at least another one) is fixed, I will send a PR to also execute the input tests with Pydantic.

@Gobot1234 Gobot1234 merged commit c2bcd31 into danielgtaylor:master Oct 5, 2024
19 checks passed
@Gobot1234
Copy link
Collaborator

I forget to mention: this problem makes some of the tests from test_inputs.py fail. The problem only appears when plugin_output_package is manually set to "tests.output_betterproto_pydantic", which is not the case by default. Once this problem (and at least another one) is fixed, I will send a PR to also execute the input tests with Pydantic.

That would be a huge help actually

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 this pull request may close these issues.

Pydantic validation error when creating instance without parameter of message with oneof
2 participants