Skip to content

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

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

Closed
nicktbgch opened this issue Jan 22, 2020 · 1 comment · Fixed by #130
Labels
bug Something isn't working help wanted Extra attention is needed medium Medium effort issue, can fit in a single PR
Milestone

Comments

@nicktbgch
Copy link

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

@danielgtaylor danielgtaylor added bug Something isn't working help wanted Extra attention is needed labels Jan 31, 2020
@boukeversteegh boukeversteegh added the medium Medium effort issue, can fit in a single PR label May 25, 2020
@boukeversteegh boukeversteegh added this to the Better Fields milestone May 25, 2020
@boukeversteegh
Copy link
Collaborator

Also see #74 for an example of the same error happening for immediate self-recursive messages

@boukeversteegh boukeversteegh changed the title maximum recursion depth hit on encoding initial default values Indirect recursive message - RecursionError: maximum recursion depth hit on encoding initial default values Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed medium Medium effort issue, can fit in a single PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants