-
Notifications
You must be signed in to change notification settings - Fork 289
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
Reparse all extensions, not just unrecognized ones #3344
Conversation
…am's linked in registry of extensions when handling custom options in end-user schemas
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
@@ -22,6 +22,8 @@ import ( | |||
// ReparseUnrecognized uses the given resolver to parse any unrecognized fields in the | |||
// given reflectMessage. It does so recursively, resolving any unrecognized fields in | |||
// nested messages. | |||
// | |||
// Deprecated: Use ReparseExtensions instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason we need to keep this around? If it's still used in core, refactor core to not use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think description answers this - yes, force other repos to refactor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
When handling user-provided schemas (images, file descriptor sets, etc), we already reparse unrecognized fields, since custom options will usually be unrecognized, but we need all fields recognized in order to serialize deterministically.
However, we really need to re-parse all extensions (and thus all custom options), because if any are recognized, it means we're using the program's linked-in global registry of extensions, which could have a different definition from the extension as it is defined in the schema we are handling.
So this adds a new
ReparseExtensions
and deprecatedReparseUnrecognized
. The new function will reparsed unrecognized fields (since they are usually unrecognized extensions), but it will also reparse recognized extensions -- by serializing them to bytes and then de-serializing using the proper resolver.I left the old one around, but deprecated, since it is used outside of this repo. But if we're okay with forcing the other repos to update all call sites in the same PR that updates the dependency, I can remove it.