-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
proto: panics on handwritten types that directly embed generated messages #668
Comments
What version of the proto package is this? I'm having a hard time correlating |
You mention that you are using hand-rolled messages, which is not something we support. The proto package currently assumes all messages were generated by That being said, we're going to need a minimized reproduction that we can run in order to address this. |
I will work to create a minimum reproducible example. grpc code is vendrored from tag v1.14.0 that was just released {
"checksumSHA1": "Pyou8mceOASSFxc7GeXZuVdSMi0=",
"path": "github.com/golang/protobuf/proto",
"revision": "b4deda0973fb4c70b50d226b1af49f3da59f5265",
"revisionTime": "2018-04-30T18:52:41Z",
"version": "v1.1.0",
"versionExact": "v1.1.0"
}, old proto-gen-go was checked out and built on 2018-01-19 "Handrolled" is equivalent to "old code" in this case - these items are no different than any other older proto generated code. As for the "everything proto-based need to be generated with latest version" ... that is a really So, in essence, by introducing these changes (table parsing, XXX), you now disallow to import anything that implements old proto interface contract (aka old code)? |
Since I am not 100% sure how to attach multiple files to an issue, I created repo with code that is quite close to what we are doing https://github.com/tandr/bug668 |
Whether |
It depends on how often I have to use proto.Equals, no? |
I'm not sure what you mean? Before replying, can you open a separate issue on the performance of |
Thank you for the reproducer. I am able to reproduce it on my end. |
Thanks Joe, lets fix this one first, performance is something we will address later. |
Alright, I struggled with this for a while, and I have some bad news and good news. The bad news: there's not really anything we can do on our end to fix this.
Now the good news. There are some (hopefully not too intrusive) workarounds:
diff --git a/bug668_test.go b/bug668_test.go
index 67654ff..b7dc95f 100644
--- a/bug668_test.go
+++ b/bug668_test.go
@@ -30,9 +31,11 @@ func TestDbBlock_packUnpack(t *testing.T) {
}
}
+type BlockNoMethods Block
+
// block wrapper as possible additional meta info holder
type dbBlock struct {
- *Block `protobuf:"bytes,1,opt,name=block" json:"block,omitempty"`
+ *BlockNoMethods `protobuf:"bytes,1,opt,name=block" json:"block,omitempty"`
}
// fulfilling Message interface
@@ -52,11 +55,11 @@ func unpackBlock(value []byte) (*Block, error) {
log.Fatalf("cannot un-marshall block %v, error=%v", dbBlock.BlockId, err)
}
- return dbBlock.Block, err
+ return (*Block)(dbBlock.BlockNoMethods), err
}
func packBlock(b *Block) ([]byte, error) {
- dbBlock := dbBlock{b}
+ dbBlock := dbBlock{(*BlockNoMethods)(b)}
buf, err := proto.Marshal(&dbBlock)
diff --git bug668_test.go bug668_test.go
index 67654ff..72e2b66 100644
--- bug668_test.go
+++ bug668_test.go
@@ -35,6 +36,9 @@ type dbBlock struct {
*Block `protobuf:"bytes,1,opt,name=block" json:"block,omitempty"`
}
+func (*dbBlock) XXX_Unmarshal() {}
+func (*dbBlock) XXX_Marshal() {}
+
// fulfilling Message interface
func (m *dbBlock) Reset() { *m = dbBlock{} }
func (m *dbBlock) String() string { return proto.CompactTextString(m) } Applying options 1, 2, or 3 fixed the test you provided. |
Thanks Joe. Stopping embedding sounds like a plan. (Other 2 solutions are just hacks - 2 is "just" a hack, 3 is a "go try to figure it out later, hehe" hack, sorry). On a side note: For XXX_ methods: maybe it would be easier if you would create "MessageXXX" interface (that fulfills Message too) and just specify that newly generated code implements it instead. And then who wants these extra fields will have them (we don't :) ) Tagging version of protobuf (and protoc-gen-go) right before that change will be much appreciated. (rant) As you probably can see, I don't like this XXX_ thing... It is extremely intrusive, it breaks ability for generated classed to be used as nice POCs, and it breaks code that was nicely working before (using classes as map keys). Now I need to introduce proxies or maintain POCs myself (with all the pains of getting out of sync attached...). Since autogenerated POCs were SO convenient, we are using these generated classes (types) everywhere across 3 different languages ... (/rant sorry=true) |
The issues your bringing up about XXX is something we're aware of. We're working on the next generation implementation of Anyways, I'm glad removing embedding will fix this for you. |
Ok, I am trying to convert our code (pre-XXX) to the latest protoc-gen-go and... I am seriously thinking about switching back to json.
Side effects so far
and the panic stack is something like this
The text was updated successfully, but these errors were encountered: