[BUG][Python] model template __copy__ refers to new_cls (undefined)
Created by: tuanchien
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The Python generator template's __copy__
function refers to new_cls
, which is not defined in the function.
This propagates into the generated model_utils.py
file. It will result in failed operations if you try to copy()
an OpenApiModel
object.
openapi-generator version
This is present in the master branch but also 5.3.0
OpenAPI declaration file content or url
This is reproducible using the petstore sample already present in the repo.
Generation Details
None. Use petstore sample.
Steps to reproduce
From the openapi-generator/samples/client/petstore/python
directory, launch Python and run
import petstore_api
from petstore_api.model.class_model import ClassModel
import copy
a = ClassModel()
b = copy.deepcopy(a) # OK
c = copy.copy(a) # Raises an error
It produces an error like:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/copy.py", line 84, in copy
return copier(x)
File "/home/user/openapi-generator/samples/client/petstore/python/petstore_api/model_utils.py", line 195, in __copy__
return new_cls.__new__(cls, **self.__dict__)
NameError: name 'new_cls' is not defined
Related issues/PRs
Suggest a fix
return cls.__new__(cls, **self.__dict__)