Skip to content
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

[BUG][Python] model template __copy__ refers to new_cls (undefined) #10856

Closed
5 of 6 tasks
tuanchien opened this issue Nov 15, 2021 · 1 comment
Closed
5 of 6 tasks

[BUG][Python] model template __copy__ refers to new_cls (undefined) #10856

tuanchien opened this issue Nov 15, 2021 · 1 comment

Comments

@tuanchien
Copy link
Contributor

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.

See:

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

Change


to

            return cls.__new__(cls, **self.__dict__)
@tuanchien tuanchien changed the title [BUG][Python] model_template __copy__ refers to new_cls (undefined) [BUG][Python] model template __copy__ refers to new_cls (undefined) Nov 15, 2021
aroelo pushed a commit to The-Academic-Observatory/observatory-platform that referenced this issue Dec 15, 2021
@tuanchien
Copy link
Contributor Author

Fixed by PR #11792

aroelo pushed a commit to The-Academic-Observatory/observatory-platform that referenced this issue Apr 8, 2022
aroelo pushed a commit to The-Academic-Observatory/observatory-platform that referenced this issue May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants