From 626140f5f7ac6b11bfc453778ab595d1d1a6ca7c Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 27 Sep 2026 16:32:18 +0200 Subject: [PATCH] THRIFT-6384: Read a -remote container argument by its field id, not its position Client: go The Go -remote stub decoded a container argument with ReadField, but the args struct names its read methods after the field id, so the stub did not compile when a container argument's id differs from its position or is implicit (ReadField_N). Apache IoTDB's confignode.thrift hits both. Co-Authored-By: Claude Opus 5.5 --- compiler/cpp/src/thrift/generate/t_go_generator.cc | 9 +++++++-- lib/go/test/ServicesTest.thrift | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc index 8bab9ae0650..3a9ee0a67ff 100644 --- a/compiler/cpp/src/thrift/generate/t_go_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc @@ -3112,8 +3112,13 @@ void t_go_generator::generate_service_remote(t_service* tservice) { << '\n'; f_remote << indent() << "containerStruct" << i << " := " << argumentsModule << ".New" << argumentsName << "()" << '\n'; - f_remote << indent() << err2 << " := containerStruct" << i << ".ReadField" << (i + 1) << "(context.Background(), " - << jsProt << ")" << '\n'; + // The args struct names its read methods after the field id, which need not be the + // argument's position, and is negative (ReadField_N) when the IDL gives none. + int32_t field_id = args[i]->get_key(); + string read_method = field_id < 0 ? "ReadField_" + std::to_string(-field_id) + : "ReadField" + std::to_string(field_id); + f_remote << indent() << err2 << " := containerStruct" << i << "." << read_method + << "(context.Background(), " << jsProt << ")" << '\n'; f_remote << indent() << "if " << err2 << " != nil {" << '\n'; indent_up(); f_remote << indent() << "Usage()" << '\n'; diff --git a/lib/go/test/ServicesTest.thrift b/lib/go/test/ServicesTest.thrift index 666197f15b7..7393e209d51 100644 --- a/lib/go/test/ServicesTest.thrift +++ b/lib/go/test/ServicesTest.thrift @@ -115,4 +115,8 @@ service container_test_parent { service container_test extends container_test_parent { void child_only_func(1: set s) + // The -remote stub must read a container argument by its field id, which + // need not be its position, and is negative when the IDL gives none. + void nonpositional_id_func(1: i32 a, 3: map m) + void implicit_id_func(list xs) }