Skip to content

protoreflect x dynamicpb interaction: should descriptors match names or be pointer-identical? #1633

Open
@stapelberg

Description

@stapelberg

Currently, when using the protoreflect package, the descriptors have to be pointer-identical: https://github.com/protocolbuffers/protobuf-go/blob/219bda23ffda544ed4cc5d5a75d34ce3b100ce51/internal/impl/message_reflect.go#L438-L443

However, the dynamicpb package is less strict and allows setting a message with a non-identical descriptor, as long as the descriptor name matches: https://github.com/protocolbuffers/protobuf-go/blob/219bda23ffda544ed4cc5d5a75d34ce3b100ce51/types/dynamicpb/dynamic.go#L589-L591

This means users can get into a situation where they mix descriptors of different sources (e.g. global proto registry vs. a custom registry) in the same message hierarchy, which ultimately means the protoreflect package will panic when calling e.g. Has.

Here’s a demo CL which contains a failing test for this issue, to illustrate: https://go.dev/cl/601255

Here’s a CL which adds validation to prevent this issue: https://go.dev/cl/500315

It’s not entirely clear to us whether we can make the validation stricter without risking breakage. If anyone has any information one way or the other, please let us know.

If we can’t make a decision on this, we could change the behavior, but also introduce an escape hatch like we have in the protoregistry package: https://github.com/protocolbuffers/protobuf-go/blob/219bda23ffda544ed4cc5d5a75d34ce3b100ce51/reflect/protoregistry/registry.go#L30-L65

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions