Fix field type inference when FieldDescriptorProto.type is unset#1369
Open
jakewisse wants to merge 1 commit intobufbuild:mainfrom
Open
Fix field type inference when FieldDescriptorProto.type is unset#1369jakewisse wants to merge 1 commit intobufbuild:mainfrom
jakewisse wants to merge 1 commit intobufbuild:mainfrom
Conversation
Some protobuf tooling (e.g. Confluent Schema Registry) omits the `type` field from FieldDescriptorProto when `type_name` is set. According to [`descriptor.proto`][0], this is valid : "If type_name is set, this need not be set." Because descriptor.proto is proto2, protobuf-es places the default value (TYPE_DOUBLE = 1) on the prototype. When `type` is absent from the wire data it is never set as an own property, and `proto.type` inherits the prototype default, causing message and enum fields to be misclassified as scalar. This resolves the field type from the registry via `type_name` when `type` is not explicitly set. From there, thread the resolved type through `getFieldPresence()`, `isPackedField()`, and `isDelimitedEncoding()` to avoid the same prototype fallback in those functions. -- [0]: https://github.com/protocolbuffers/protobuf/blob/c223b2e1fa96feac05f275853e64a87993d557a2/src/google/protobuf/descriptor.proto#L295-L296
|
|
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.
Some protobuf tooling (e.g. Confluent Schema Registry) omits the
typefield from FieldDescriptorProto whentype_nameis set. According todescriptor.proto, this is valid : "If type_name is set, this need not be set."Because descriptor.proto is proto2, protobuf-es places the default value (TYPE_DOUBLE = 1) on the prototype. When
typeis absent from the wire data it is never set as an own property, andproto.typeinherits the prototype default, causing message and enum fields to be misclassified as scalar.This resolves the field type from the registry via
type_namewhentypeis not explicitly set. From there, we thread the resolved type throughgetFieldPresence(),isPackedField(), andisDelimitedEncoding()to avoid the same prototype fallback in those functions.Fixes #1368.