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

Reparse all extensions, not just unrecognized ones #3344

Merged
merged 3 commits into from
Sep 26, 2024
Merged

Conversation

jhump
Copy link
Member

@jhump jhump commented Sep 26, 2024

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 deprecated ReparseUnrecognized. 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.

…am's linked in registry of extensions when handling custom options in end-user schemas
Copy link
Contributor

github-actions bot commented Sep 26, 2024

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedSep 26, 2024, 2:19 PM

@@ -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.
Copy link
Member

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

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@bufdev bufdev merged commit dacb299 into main Sep 26, 2024
11 checks passed
@bufdev bufdev deleted the jh/reparse-all-exts branch September 26, 2024 15:00
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.

2 participants