Derek1st
Derek1st

Reputation: 73

Python package "dpath" segments.py giving infinite recursion on a simple "isinstance" call

Attempting to use swagger codegen to auto-generate some a client library for a project I'm doing for work. Apparently swagger doesn't natively have a python version but they link to a community supported swagger-py codegen. Installed this with pip, tried running on my projects OpenAPI repo and I'm getting the error "RecursionError: maximum recursion depth exceeded in instancecheck"

Here's the stack trace:

Traceback (most recent call last):
  File "/home/user/.local/bin/swagger_py_codegen", line 8, in <module>
    sys.exit(generate())
  File "/home/user/.local/lib/python3.8/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/user/.local/lib/python3.8/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/user/.local/lib/python3.8/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/swagger_py_codegen/command.py", line 200, in generate
    for code in generator.generate():
  File "/home/user/.local/lib/python3.8/site-packages/swagger_py_codegen/base.py", line 44, in generate
    for code in g:
  File "/home/user/.local/lib/python3.8/site-packages/swagger_py_codegen/base.py", line 47, in generate
    for code in self._process():
  File "/home/user/.local/lib/python3.8/site-packages/swagger_py_codegen/jsonschema.py", line 110, in _process
    yield Schema(build_data(self.swagger))
  File "/home/user/.local/lib/python3.8/site-packages/swagger_py_codegen/jsonschema.py", line 51, in build_data
    for path, _ in swagger.search(['paths', '*']):
  File "/home/user/.local/lib/python3.8/site-packages/swagger_py_codegen/parser.py", line 118, in search
    for p, d in dpath.util.search(
  File "/home/user/.local/lib/python3.8/site-packages/dpath/util.py", line 222, in yielder
    for segments, found in dpath.segments.walk(obj):
  File "/home/user/.local/lib/python3.8/site-packages/dpath/segments.py", line 73, in walk
    for found in walk(v, location + (k,)):
  File "/home/user/.local/lib/python3.8/site-packages/dpath/segments.py", line 73, in walk
    for found in walk(v, location + (k,)):
  File "/home/user/.local/lib/python3.8/site-packages/dpath/segments.py", line 73, in walk
    for found in walk(v, location + (k,)):
  [Previous line repeated 981 more times]
  File "/home/user/.local/lib/python3.8/site-packages/dpath/segments.py", line 58, in walk
    if not leaf(obj):
  File "/home/user/.local/lib/python3.8/site-packages/dpath/segments.py", line 33, in leaf
    return isinstance(thing, leaves)
RecursionError: maximum recursion depth exceeded in __instancecheck__

If it were simply this community python implementation of swagger codegen, I'd understand, but its happening in isInstance.

It looks as though it gets to dpath site package (not familiar with this, maybe swagger_py_codegen added it), it gets to segments, and then there's a function that checks if something is a leaf.

Here's the relevant section from segments.py:

def leaf(thing):
    '''
    Return True if thing is a leaf, otherwise False.

    leaf(thing) -> bool
    '''
    leaves = (bytes, str, int, float, bool, type(None))

    return isinstance(thing, leaves)

I'm pretty sure isinstance is just part of the standard library, so its not as if I can tweak that. But looking at this leaf(thing) method from dpath, I can't see what could be causing the error.

What I've tried so far:

I tried editing segments.py to increase the max recursion count to 10,000. This just leads to running forever. I left it alone for 5 minutes and it still never completed.

So its SOME sort of infinite recursive loop, but assuming isinstance is correct, I cannot for the life of me figure out what is causing the issue from that simple leaf(thing) call

Upvotes: 1

Views: 157

Answers (0)

Related Questions