Fix optional fields in proto3#16
Merged
Merged
Conversation
Signed-off-by: adamwhats <adamlwatts@msn.com>
Signed-off-by: adamwhats <adamlwatts@msn.com>
Contributor
Author
|
Edited to add commit signoffs |
Collaborator
mhidalgo-rai
left a comment
There was a problem hiding this comment.
@adamwhats great catch, and thanks for the contribution 😃
Would you mind adding a test for Python conversion APIs too?
Signed-off-by: adamwhats <adamlwatts@msn.com>
mhidalgo-rai
requested changes
Nov 14, 2025
…s on humble Signed-off-by: adamwhats <adamlwatts@msn.com>
mhidalgo-rai
previously approved these changes
Nov 24, 2025
Signed-off-by: adamwhats <adamlwatts@msn.com>
mhidalgo-rai
approved these changes
Nov 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
I think I've found an issue with handling optional fields. To replicate, add an optional field to a message in test.proto:
After building this gives the following error:
I think this is due to proto3 internally rewriting optional fields as a 'synthetic oneof' with a leading underscore, as documented here. This then causes issues with this line line, as
.camelize()doesn't handle double underscores, hence we getoneof_type_name = HVACControlRequestOneOf_humiditySetpoint.My fix has is a small change to equivalences.py where we only add oneof field descriptors without a leading underscore to
oneof_field_sets, then a little bit of handling in the next loop below. I'm very open to feedback on this, there may well be a more elegant solution.Checklist