Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with nested enums with gRPC #395

Closed
trickleup opened this issue Jun 30, 2022 · 3 comments
Closed

Issue with nested enums with gRPC #395

trickleup opened this issue Jun 30, 2022 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@trickleup
Copy link

Thanks for a great library. I've found an issue when working with nested enums and gRPC service definitions. It looks somewhat similar to #212, but doesn't seem the same, from what I can see.

better proto version: 2.0.0b4
protoc version: 3.19.4

This proto definition works:

syntax = "proto3";

package hello;

service GreetingAPI {
  rpc SayHello (Greeting)
    returns (Greeting) {}
}

// Greeting represents a message you can tell a user.
message Greeting {
  Foo foo = 1;
}

enum Foo {
  FOO_UNSPECIFIED = 0;
}

But when I nest the enum, like this:

syntax = "proto3";

package hello;

service GreetingAPI {
  rpc SayHello (Greeting)
    returns (Greeting) {}
}

// Greeting represents a message you can tell a user.
message Greeting {
  Foo foo = 1;
  enum Foo {
    FOO_UNSPECIFIED = 0;
  }
}

It fails with the following error:

Traceback (most recent call last):
  File "/Users/johan.genberg/projects/testing/betterproto/.venv/bin/protoc-gen-python_betterproto", line 8, in <module>
    sys.exit(main())
  File "/Users/johan.genberg/projects/testing/betterproto/.venv/lib/python3.9/site-packages/betterproto/plugin/main.py", line 32, in main
    response = generate_code(request)
  File "/Users/johan.genberg/projects/testing/betterproto/.venv/lib/python3.9/site-packages/betterproto/plugin/parser.py", line 107, in generate_code
    read_protobuf_service(service, index, output_package)
  File "/Users/johan.genberg/projects/testing/betterproto/.venv/lib/python3.9/site-packages/betterproto/plugin/parser.py", line 191, in read_protobuf_service
    ServiceMethodCompiler(
  File "<string>", line 7, in __init__
  File "/Users/johan.genberg/projects/testing/betterproto/.venv/lib/python3.9/site-packages/betterproto/plugin/models.py", line 683, in __post_init__
    self.mutable_default_args  # ensure this is called before rendering
  File "/Users/johan.genberg/projects/testing/betterproto/.venv/lib/python3.9/site-packages/betterproto/plugin/models.py", line 720, in mutable_default_args
    and f.default_value_string != "None"
  File "/Users/johan.genberg/projects/testing/betterproto/.venv/lib/python3.9/site-packages/betterproto/plugin/models.py", line 486, in default_value_string
    enum = next(
StopIteration
--python_betterproto_out: protoc-gen-python_betterproto: Plugin failed with status code 1.

I run betterproto like this:

protoc -I . --python_betterproto_out=lib test_fail.proto

The error seems to be due to some naming collision. Also, it only appears if the service definition is in the file. If I remove it, the nested enum works well.

I can work around this by not nesting the enum. But still wanted to report it, see if there was a more long term fix.

@Gobot1234
Copy link
Collaborator

This has already been fixed on the master branch there's unfortunately just no full release containing the fix

@Gobot1234 Gobot1234 added the duplicate This issue or pull request already exists label Jun 30, 2022
@trickleup
Copy link
Author

Thanks for the response. Do you know when the next release will be out?

@Gobot1234
Copy link
Collaborator

Not sure the other collaborators seem to busy but it's pretty much ready to go it just needs someone to review #350 and #381

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants