RecursionError: maximum recursion depth exceeded while calling a Python object
See original GitHub issueDescribe the bug Trying to create code from an OpenAPI spec fails with a RecursionError.
To Reproduce
Example schema:
https://developer.here.com/documentation/routing-api/swagger/v8.yaml
Used commandline:
$ datamodel-codegen --url https://developer.here.com/documentation/routing-api/swagger/v8.yaml --input-file-type openapi --output result_model.py
Expected behavior No RecursionError
Version:
- OS: Ubuntu 22.04
- Python version: 3.8
- datamodel-code-generator version: 0.13.0
Additional context
Not sure if the OpenAPI is defect or this package.
Traceback (most recent call last):
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/__main__.py", line 541, in main
generate(
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/__init__.py", line 367, in generate
results = parser.parse()
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/base.py", line 449, in parse
self.parse_raw()
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/openapi.py", line 393, in parse_raw
self.parse_raw_obj(
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 1149, in parse_raw_obj
self.parse_obj(name, JsonSchemaObject.parse_obj(raw), path)
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 1164, in parse_obj
self.parse_object(name, obj, path)
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 599, in parse_object
fields=self.parse_object_fields(
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 545, in parse_object_fields
field_type = self.parse_item(modular_name, field, [*path, field_name])
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 645, in parse_item
return self.parse_array_fields(
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 753, in parse_array_fields
data_types=self.parse_list_item(
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 720, in parse_list_item
return [
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 721, in <listcomp>
self.parse_item(
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 639, in parse_item
return self.get_ref_data_type(item.ref)
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 436, in get_ref_data_type
return self.data_type(reference=reference)
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/types.py", line 209, in __init__
super().__init__(**values)
File "/home/eifinger/.cache/pypoetry/virtualenvs/here-routing-cgjRCcGK-py3.8/lib/python3.8/site-packages/datamodel_code_generator/reference.py", line 45, in __init__
super().__init__(**values)
File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
File "pydantic/main.py", line 1038, in pydantic.main.validate_model
File "pydantic/fields.py", line 857, in pydantic.fields.ModelField.validate
File "pydantic/fields.py", line 1074, in pydantic.fields.ModelField._validate_singleton
File "pydantic/fields.py", line 1121, in pydantic.fields.ModelField._apply_validators
File "pydantic/class_validators.py", line 313, in pydantic.class_validators._generic_validator_basic.lambda12
File "pydantic/main.py", line 679, in pydantic.main.BaseModel.validate
File "pydantic/main.py", line 605, in pydantic.main.BaseModel._copy_and_set_values
File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.8/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/lib/python3.8/copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.8/copy.py", line 205, in _deepcopy_list
append(deepcopy(a, memo))
File "/usr/lib/python3.8/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
...
RecursionError: maximum recursion depth exceeded while calling a Python object
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:6 (1 by maintainers)
Top Results From Across the Web
maximum recursion depth exceeded while calling a Python ...
This means that each call to your recursive function will create a function call stack and because there is a limit of stack...
Read more >Python RecursionError: Maximum Recursion Depth ...
A Python RecursionError exception is raised when the execution of your program exceeds the recursion limit of the Python interpreter.
Read more >Python maximum recursion depth exceeded in comparison
The “maximum recursion depth exceeded in comparison” error is raised when you try to execute a function that exceeds Python's built in recursion ......
Read more >maximum recursion depth exceeded while calling a Python ...
When the interpreter detects that the maximum depth for recursion has reached, it throws the recursionerror ...
Read more >Python: Maximum Recursion Depth Exceeded [How to Fix It]
The maximum recursion depth in Python is 1000. To check it, call sys.getrecursionlimit() function. To change it, call sys.setrecursionlimit().
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also encountered this problem.
It seems like pydantic 1.9.1 added
deepcopy
to model validation:(from the release notes)
This isn’t apparent in the
datamodel-code-generator
project because it’s currently locked on Pydantic1.9.0
.The fix seems simple enough, hopefully I can a get a PR in today.
@pmbrull thank you doing that, pinning
markupsafe==2.0.1
and following the fix from this link helped: https://github.com/koxudaxi/fastapi-code-generator/issues/232#issuecomment-1059146715