python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

Import not generated for package/module if only referenced in service declaration.

Open adriangaro opened this issue 2 years ago • 2 comments

As a basic example I have the below, the generated service will not import the test package, however if i reference any message in the return it imports it correctly.


package test;

import "test2.proto";

message TestMessage {}

service Test {
  rpc test(test2.DemoRequest) returns (TestMessage);
}

From a shallow look seems to stem from the ServiceMethodCompiler.__post_init__ method. The return type is referenced using py_output_message_type which calls get_type_reference which adds it to imports, however nowhere in the __post_init__ is the input type referenced for it to be added with get_type_reference to imports.

adriangaro avatar Sep 27 '22 14:09 adriangaro

Adding the line self.py_input_message_type at line 692 in that file seems to work, also betterproto version 2.0.0-beta5

adriangaro avatar Sep 27 '22 14:09 adriangaro

For those with this issue who note that the line number is out of date on the current build, here's where that was referring to: https://github.com/danielgtaylor/python-betterproto/blob/8fbf4476a8f4a9c9a8bb07a64cc0bbb379e0afa8/src/betterproto/plugin/models.py#L688-L694

ABaumher avatar May 31 '23 15:05 ABaumher