Skip to content
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

Unpacking nested "Any message" fails because typeRegistry isn't being passed along #568

Merged
merged 1 commit into from
Apr 21, 2022

Conversation

BenVercammen
Copy link
Contributor

While calling .toProto3Json() I kept bumping into the error message The type of the Any message (...) is not in the given typeRegistry. even though I had passed along a TypeRegistry with the related GeneratedMessage types. After some stepping through the code, I found out that the typeRegistry parameter was not passed along while unpacking.

I fixed the issue for my use case, but still have to write a test for it, though I'm not sure when I can get around to it. Anyhow, I already wanted to open the PR as to be able to receive feedback on any potential harm I'd be doing with this fix. I'll try to write a test as soon as I can, probably around the weekend.

I'm pretty new to protobuf and even dart in general, so if my terminlogy is off (eg: in the commit message) feel free to correct me :-)

@sigurdm
Copy link
Collaborator

sigurdm commented Jan 7, 2022

I think this looks good.

Could you create a test revealing this also?

@BenVercammen
Copy link
Contributor Author

BenVercammen commented Jan 7, 2022

Could you create a test revealing this also?

Just pushed a test showing this. Only the one in the "encode" group was failing, but for completeness sake I also added a counterpart test in the "encode" group.

So the situation occurs when you have a message with an Any field that contains a message with an Any field. When the nested field is being unpacked in order to get a JSON value out of it, the TypeRegistry became missing.

Feel free to rename/reshuffle the created proto messages if you like. I think it might already work with only a single AnyMessage message, but this setup reflected the use case that lead me to discover this issue.

@BenVercammen BenVercammen marked this pull request as ready for review January 7, 2022 18:07
@BenVercammen
Copy link
Contributor Author

Is it possible to re-run the wokflow? I think I've fixed all the issues...

@BenVercammen
Copy link
Contributor Author

Any idea when this would be merged?

Copy link
Member

@osa1 osa1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay @BenVercammen. I noticed a few redundant lines in the test proto, if you could remove those I'll merge this.

@osa1 osa1 merged commit 96bdf38 into google:master Apr 21, 2022
osa1 added a commit to osa1/protobuf.dart that referenced this pull request Apr 21, 2022
@BenVercammen BenVercammen deleted the nested-type-registry-fix branch April 21, 2022 13:56
osa1 added a commit to osa1/protobuf.dart that referenced this pull request Jun 28, 2022
Follow official protobuf style guide:

1. License header (if applicable)
2. File overview
3. Syntax
4. Package
5. Imports (sorted)
6. File options
7. Everything else

Internally we want a `package` line in every proto, and it's easier to
do add `package` lines to protos than to add them as exceptions.

License headers added the old files based on creation date.

protos in google/protobuf are not updated as they are copied from
protoc.

The proto file `unittest_nested_any.proto` was added google#568. Since it's
not copied from protoc I moved it to test/protos.

Fixes google#692
osa1 added a commit that referenced this pull request Jun 28, 2022
Follow official protobuf style guide:

1. License header (if applicable)
2. File overview
3. Syntax
4. Package
5. Imports (sorted)
6. File options
7. Everything else

Internally we want a `package` line in every proto, and it's easier to
do add `package` lines to protos than to add them as exceptions.

License headers added the old files based on creation date.

protos in google/protobuf are not updated as they are copied from
protoc.

The proto file `unittest_nested_any.proto` was added #568. Since it's
not copied from protoc I moved it to test/protos.

Fixes #692
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.

3 participants