Skip to content

Indirect recursive message - RecursionError: maximum recursion depth hit on encoding initial default values #13

Closed
@nicktbgch

Description

@nicktbgch

Hi there,
I really prefer the betterproto probuf output to Google's, so well done on that! I've come across the following issue, and narrowed it down to the simplest proto I can to reproduce.

Initialising the following proto, (after compiling with python-betterproto)

syntax = "proto3";
package schemas;

message Action {
    oneof action_oneof {
        ref not_repeated = 2;
    }
}

message ref {
    string name = 2;
    Action action = 3;
}

with a simple test = schemas.Action()

is causing recursion and a failure to create the test object. It looks as far as I can tell that its attempting to work out the default values for the initial proto.

File "<string>", line 4, in __init__
  File "/lib/python3.7/site-packages/betterproto/__init__.py", line 460, in __post_init__
    setattr(self, field.name, self._get_field_default(field, meta))
  File "/lib/python3.7/site-packages/betterproto/__init__.py", line 593, in _get_field_default
    value = t()
  File "<string>", line 3, in __init__
  File "/lib/python3.7/site-packages/betterproto/__init__.py", line 460, in __post_init__
    setattr(self, field.name, self._get_field_default(field, meta))

repeated then
RecursionError: maximum recursion depth exceeded while calling a Python object

When the proto definition is changed to

message ref {
    string name = 2;
    repeated Action action = 3;
}

then the recursion error does not occur.

The standard 'protoc --python_out=' does not exhibit this behaviour, hence I thought I'd raise this.
cheers
Nick

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededmediumMedium effort issue, can fit in a single PR

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions