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

Disappears from the generated `ServiceBase` if there is a `ID` in the name [2.0.0b3] #230

Open isac322 opened 3 years ago

isac322 commented 3 years ago

Env

Python: 3.9 protoc: 3.15.6 betterproto: 2.0.0b3 OS: linux


Given proto

syntax = "proto3";
package com.test.v1;
import "google/protobuf/empty.proto";

service TestService {
  rpc Test(PublisherUserID) returns (google.protobuf.Empty);
}

message PublisherUserID {
  int64 publisher_user_id = 1;
}

Generated TestServiceBase

Parameter PublisherUserID of test() disappered.

class TestServiceBase(ServiceBase):
    async def test(self) -> "betterproto_lib_google_protobuf.Empty":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def __rpc_test(self, stream: grpclib.server.Stream) -> None:
        request = await stream.recv_message()

        request_kwargs = {}

        response = await self.test(**request_kwargs)
        await stream.send_message(response)

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/com.test.v1.TestService/Test": grpclib.const.Handler(
                self.__rpc_test,
                grpclib.const.Cardinality.UNARY_UNARY,
                PublisherUserId,
                betterproto_lib_google_protobuf.Empty,
            ),
        }

Midified proto

Rename ID to Id

syntax = "proto3";
package com.test.v1;
import "google/protobuf/empty.proto";

service TestService {
  rpc Test(PublisherUserId) returns (google.protobuf.Empty);
}

message PublisherUserId {
  int64 publisher_user_id = 1;
}

Generated TestServiceBase

class TestServiceBase(ServiceBase):
    async def test(
        self, publisher_user_id: int
    ) -> "betterproto_lib_google_protobuf.Empty":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def __rpc_test(self, stream: grpclib.server.Stream) -> None:
        request = await stream.recv_message()

        request_kwargs = {
            "publisher_user_id": request.publisher_user_id,
        }

        response = await self.test(**request_kwargs)
        await stream.send_message(response)

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/com.test.v1.TestService/Test": grpclib.const.Handler(
                self.__rpc_test,
                grpclib.const.Cardinality.UNARY_UNARY,
                PublisherUserId,
                betterproto_lib_google_protobuf.Empty,
            ),
        }
kilimnik commented 3 years ago

I noticed the same issue with the word VPN. Maybe there is something weird with multiple uppercase letters behind each other.