Skip to content

Fix field type inference when FieldDescriptorProto.type is unset#1369

Open
jakewisse wants to merge 1 commit intobufbuild:mainfrom
jakewisse:bugfix/file-descriptor-proto-type-optional
Open

Fix field type inference when FieldDescriptorProto.type is unset#1369
jakewisse wants to merge 1 commit intobufbuild:mainfrom
jakewisse:bugfix/file-descriptor-proto-type-optional

Conversation

@jakewisse
Copy link

@jakewisse jakewisse commented Mar 4, 2026

Some protobuf tooling (e.g. Confluent Schema Registry) omits the type field from FieldDescriptorProto when type_name is set. According to descriptor.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 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, we thread the resolved type through getFieldPresence(), isPackedField(), and isDelimitedEncoding() to avoid the same prototype fallback in those functions.

Fixes #1368.

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
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

Fields are incorrectly classified as scalar when type omitted from FieldDescriptorProto

3 participants