Skip to content

Remove anypb.Any type url prefix "type.googleapis.com" #13669

@amaury1093

Description

@amaury1093

Summary of Bug

IMPORTANT: this is about the official google.golang.org/protobuf Any, not gogo where we already have a custom Any type to do this sort of stuff.

When wrapping a protobuf message inside a protoreflect-based anypb.Any, the type url is prefixed with "type.googleapis.com"

msg := &bankv1beta1.MsgSend{}
any, _ := anypb.New(msg)
fmt.Println(any.TypeUrl)

// Expected: "/cosmos.bank.v1beta1.MsgSend"
// Actual:   "type.googleapis.com/cosmos.bank.v1beta1.MsgSend"

The culprit is this line:

https://github.com/protocolbuffers/protobuf-go/blob/6875c3d7242d1a3db910ce8a504f124cb840c23a/types/known/anypb/any.pb.go#L266

Affected functions and methods are:

  • anypb.New
  • anypb.MarshalFrom
  • anypb.Any#MarshalFrom

Note: anypb's Unmarshal functions are not affected, and work as expected, as our pulsar types register themselves without the prefix.

Version

v0.47+

Proposal

Idea 1: Create our own MarshalFrom function, add docs to not use anypb's ones

This means that we would replicate our own MarshalFrom and New functions inside the SDK (same one as anypb without the prefix), and tell users to not use the 3 functions mentioned above, but our own implementations

Con:

  • There's a (pretty high IMO) risk that users won't be aware of this

Idea 2: Create our own Any type

It would be a copy/paste of anypb's Any, except for the typeURL prefix.

Con:

  • not using the official version

Idea 3: Embrace "type.googleapis.com"

Start prefixing "type.googleapis.com" in all of our Anys

Cons:

  • doesn't look nice, it's long
  • migrations are needed

Metadata

Metadata

Assignees

Labels

C: ProtoProto definition and proto release

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions