danielgtaylor / python-betterproto

Clean, modern, Python 3.6+ code generator & library for Protobuf 3 and async gRPC
MIT License
1.51k stars 214 forks source link

Mixed case request results in missing request parameters in generated code #271

Open simonjpartridge opened 3 years ago

simonjpartridge commented 3 years ago

Version: betterproto==2.0.0b3

Requests with capital letters in the name seem to cause an issue with constructing methods. The request parameters are not added to the method. e.g

proto file:

rpc TestCAPITALS(TestCAPITALSRequest) returns (TestCAPITALSResponse){}

message TestCAPITALSRequest{
  string name = 1;
}

message TestCAPITALSResponse{}

generated class:

async def test_capitals(self) -> "TestCapitalsResponse":

        request = TestCapitalsRequest()

        return await self._unary_unary(
            "/tumelo.transparency.v1.InstrumentPortfolioTransparency/TestCAPITALS",
            request,
            TestCapitalsResponse,
        )

we would expect a name field in the request but it is not there

jca-klk commented 2 years ago

Hi! I experienced the same thing with snake_case message names and lower-case message as well.

syntax = "proto3";

message test_req {
      string name = 1;
}

message test_resp {}

service example {
  rpc test(test_req) returns (test_resp);
}

Results in

class ExampleStub(betterproto.ServiceStub):
    async def test(self) -> "TestResp":

        request = TestReq()

        return await self._unary_unary("/example/test", request, TestResp)

It fails identically with

When using message Testreq it behaves as expected:

class ExampleStub(betterproto.ServiceStub):
    async def test(self, *, name: str = "") -> "TestResp":

        request = Testreq()
        request.name = name

        return await self._unary_unary("/example/test", request, TestResp)

Protocol Buffers Version 3 Language Specification allows such identifiers in messageName and they are found in the wild.

Versions: