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

Version 2.0.0b4 fail to generate plugins concurrently #312

Open TamirFriedman-RecoLabs opened 2 years ago

TamirFriedman-RecoLabs commented 2 years ago

Usage fails with BetterProto 2.0.0b4 Version

$ buf generate -vvv proto
E0105 15:39:19.511094 1771702 template.go:991] created a body with 0 properties in the message, this might be unintended: name:"ModifyTileDisplayStateRequest"  field:{name:"tile_name"  number:1  label:LABEL_OPTIONAL  type:TYPE_STRING  json_name:"tileName"}  field:{name:"tile_state"  number:2  label:LABEL_OPTIONAL  type:TYPE_ENUM  type_name:".reco.services.v1.TileDisplayState"  json_name:"tileState"}
Traceback (most recent call last):
  File "/usr/local/bin/protoc-gen-python_betterproto", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/betterproto/plugin/main.py", line 32, in main
    response = generate_code(request)
  File "/usr/local/lib/python3.9/dist-packages/betterproto/plugin/parser.py", line 107, in generate_code
    read_protobuf_service(service, index, output_package)
  File "/usr/local/lib/python3.9/dist-packages/betterproto/plugin/parser.py", line 191, in read_protobuf_service
    ServiceMethodCompiler(
  File "<string>", line 7, in __init__
  File "/usr/local/lib/python3.9/dist-packages/betterproto/plugin/models.py", line 683, in __post_init__
    self.mutable_default_args  # ensure this is called before rendering
  File "/usr/local/lib/python3.9/dist-packages/betterproto/plugin/models.py", line 720, in mutable_default_args
    and f.default_value_string != "None"
  File "/usr/local/lib/python3.9/dist-packages/betterproto/plugin/models.py", line 486, in default_value_string
    enum = next(
StopIteration
Failure: failed to generate plugins concurrently: failed to execute plugins concurrently: failed to generate: exit status 1.

Replacing to older version

$ pip install betterproto[compiler]==2.0.0b3
Collecting betterproto[compiler]==2.0.0b3
  Downloading betterproto-2.0.0b3-py3-none-any.whl (59 kB)
     |████████████████████████████████| 59 kB 611 kB/s 
Installing collected packages: betterproto
  Attempting uninstall: betterproto
    Found existing installation: betterproto 2.0.0b4
    Uninstalling betterproto-2.0.0b4:
      Successfully uninstalled betterproto-2.0.0b4
Successfully installed betterproto-2.0.0b3

Usage succeed with BetterProto 2.0.0b3 Version

$ buf generate -vvv proto
E0105 15:54:45.424446 1781827 template.go:991] created a body with 0 properties in the message, this might be unintended: 
Writing __init__.py
Writing google/__init__.py
Writing google/api/__init__.py
Writing google/longrunning/__init__.py
Writing google/rpc/__init__.py
Writing grpc/__init__.py
Writing grpc/gateway/__init__.py
Writing grpc/gateway/protoc_gen_openapiv2/__init__.py
Writing grpc/gateway/protoc_gen_openapiv2/options/__init__.py
Writing validate/__init__.py
Gobot1234 commented 2 years ago

Hi, sorry about this could you perhaps attach the file that causes this error?

efokschaner commented 2 years ago

Given that I removed mutable_default_args this might work after https://github.com/danielgtaylor/python-betterproto/pull/311

@TamirFriedman-RecoLabs if you want to try the efokschaner:methods-take-messages branch to find out it would help.

roblabla commented 2 years ago

The error is caused by embedded enums. I have a similar error, here's a minimal reproducer:

syntax = "proto3";

package test;

message Msg {
    enum InnerEnum {
        ENUM_ZERO = 0;
        ENUM_ONE = 1;
    }
    InnerEnum en = 1;
}

message MsgReply {}

service Service {
    rpc Method(Msg) returns (MsgReply);
}

Moving InnerEnum outside msg stops the error from occuring. I suspect the issue is due to the new support for open enums.

roblabla commented 2 years ago

This appears to be fixed by d260f071e01657287888e15b73623305b56b4d9f somehow

Gobot1234 commented 2 years ago

The error is caused by embedded enums. I have a similar error, here's a minimal reproducer:


syntax = "proto3";

package test;

message Msg {

    enum InnerEnum {

        ENUM_ZERO = 0;

        ENUM_ONE = 1;

    }

    InnerEnum en = 1;

}

message MsgReply {}

service Service {

    rpc Method(Msg) returns (MsgReply);

}

Moving InnerEnum outside msg stops the error from occuring. I suspect the issue is due to the new support for open enums.

I'll add a few tests so that issues like this don't happen again