Skip to content

fix(grpc-transcode): resolve proto_id given as an integer - #13811

Open
alirezashamsabad wants to merge 1 commit into
apache:masterfrom
alirezashamsabad:fix/grpc-transcode-proto-id-type
Open

fix(grpc-transcode): resolve proto_id given as an integer#13811
alirezashamsabad wants to merge 1 commit into
apache:masterfrom
alirezashamsabad:fix/grpc-transcode-proto-id-type

Conversation

@alirezashamsabad

Copy link
Copy Markdown

Description

id_schema allows a resource id to be either a string or an integer, and the
grpc-transcode docs type proto_id as string/integer. But create_proto_obj
compares the configured proto_id against the stored id with ==, and in Lua
1 == "1" is false. The admin API stores the id as a string, so any Route
configuring "proto_id": 1 fails to resolve its proto:

proto load error: failed to find proto by id: 1

Reproducer against master: two Routes over the same proto, one with the id as a
string and one as an integer.

curl "http://127.0.0.1:9180/apisix/admin/routes/1" -H "X-API-KEY: $admin_key" -X PUT -d '
{
  "uri": "/str",
  "plugins": { "grpc-transcode": { "proto_id": "1", "service": "helloworld.Greeter", "method": "SayHello" } },
  "upstream": { "scheme": "grpc", "type": "roundrobin", "nodes": { "127.0.0.1:10051": 1 } }
}'

curl "http://127.0.0.1:9180/apisix/admin/routes/2" -H "X-API-KEY: $admin_key" -X PUT -d '
{
  "uri": "/int",
  "plugins": { "grpc-transcode": { "proto_id": 1, "service": "helloworld.Greeter", "method": "SayHello" } },
  "upstream": { "scheme": "grpc", "type": "roundrobin", "nodes": { "127.0.0.1:10051": 1 } }
}'

/str transcodes, /int returns an error and logs failed to find proto by id: 1.

This compares both sides as strings, matching how graphql-proxy-cache and
upstream.lua already normalize ids.

Which issue(s) this PR fixes:

Fixes #8952, which was closed as
stale without a fix. The report is still reproducible on master.

Tests

Two blocks added to t/plugin/grpc-transcode.t: a Route configured with an
integer proto_id, and a request through it. Both fail without the change and
pass with it.

Developed with AI assistance; design decisions, review and testing are my own.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change (not needed: the docs already type proto_id as string/integer; this makes the code match them)
  • I have verified that this change is backward compatible (If it is not backward compatible, please discuss on the APISIX mailing list first)

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 12, 2026
@alirezashamsabad

Copy link
Copy Markdown
Author

Related: #13812 adds a feature to the same plugin. The two are independent and do
not conflict; this one is the smaller, self-contained fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: failed to find proto by id in grpc-transcode plugin

1 participant