python-trio / purerpc

Native, async Python gRPC client and server implementation supporting asyncio, uvloop, and trio
Apache License 2.0
217 stars 15 forks source link

Wrong fully qualified message names for imported messages #1

Closed penguin138 closed 6 years ago

penguin138 commented 6 years ago

When generating *_grpc.py from *.proto names declared in imported protos have wrong fully qualified names. For example if I have the following proto named A.proto:

syntax = "proto3";

import "B.proto";

service ServiceA {
  rpc MethodA(InputEntityB) returns (OutputEntityB);
}

And proto named B.proto:

syntax = "proto3";

package B_package;

message InputEntityB {
     ....
}

message OutputEntityB {
     ....
}

Then in generated A_grpc.py MethodA will be defined as follows:

    service_obj.add_method(
            "MethodA", self.MethodA,
            RPCSignature(
                Cardinality.UNARY_UNARY, A.B_package.InputEntityB, A.B_package.OutputEntityB))

However, MethodA should be defined like this:

    service_obj.add_method(
            "MethodA", self.MethodA,
            RPCSignature(
                Cardinality.UNARY_UNARY, B.InputEntityB, B.OutputEntityB))

As you can see, generation code does not take into account the fact that messages used when defining services can be imported from other protos. So, I've put together a fix that solves this problem.