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

[python-nextgen] fix #16010 circular refs lead to no imports #16199

Merged
merged 9 commits into from
Jul 29, 2023

Conversation

fa0311
Copy link
Contributor

@fa0311 fa0311 commented Jul 26, 2023

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • In case you are adding a new generator, run the following additional script :
    ./bin/utils/ensure-up-to-date
    
    Commit all changed files.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Overview

fix #16010

Circular import seem to be skipped in the current master.

if (circularImports.get(cp.dataType).contains(classname)) {
// cp.dataType import map of set contains this model (classname), don't import
LOGGER.debug("Skipped importing {} in {} due to circular import.", cp.dataType, classname);

@fa0311 fa0311 marked this pull request as draft July 26, 2023 21:51
@fa0311
Copy link
Contributor Author

fa0311 commented Jul 26, 2023

Inherited objects are being imported unnecessarily late.
This will be corrected later.

@fa0311
Copy link
Contributor Author

fa0311 commented Jul 27, 2023

Inherited objects are being imported unnecessarily late.
This will be corrected later.

I have fixed this
This was a typo on my part...

@fa0311 fa0311 marked this pull request as ready for review July 27, 2023 10:51
@wing328
Copy link
Member

wing328 commented Jul 28, 2023

@fa0311 thanks for the PR but the CI tests failed: https://app.circleci.com/pipelines/github/OpenAPITools/openapi-generator/24934/workflows/5d9866ce-79a9-4974-822e-100372bde560/jobs/74478

Can you please take a look when you've time?

To run the petstore server locally, please refer to https://github.com/OpenAPITools/openapi-generator/wiki/Integration-Tests

@fa0311
Copy link
Contributor Author

fa0311 commented Jul 28, 2023

thanks for the PR but the CI tests failed

The test is failing due to an existing bug.
#16151

Current PythonNextgenPetstoreTests rarely work because they do not do circular import references.

@fa0311
Copy link
Contributor Author

fa0311 commented Jul 28, 2023

Merge #16208 and the test was successful.

@wing328
Copy link
Member

wing328 commented Jul 28, 2023

but the tests in CI stills failed: https://app.circleci.com/pipelines/github/OpenAPITools/openapi-generator/24934/workflows/5d9866ce-79a9-4974-822e-100372bde560/jobs/74478

___________________ ERROR collecting tests/test_store_api.py ___________________
tests/test_store_api.py:16: in <module>
    import petstore_api
petstore_api/__init__.py:20: in <module>
    from petstore_api.api.another_fake_api import AnotherFakeApi
petstore_api/api/__init__.py:4: in <module>
    from petstore_api.api.another_fake_api import AnotherFakeApi
petstore_api/api/another_fake_api.py:24: in <module>
    from petstore_api.models.client import Client
petstore_api/models/__init__.py:31: in <module>
    from petstore_api.models.circular_reference_model import CircularReferenceModel
petstore_api/models/circular_reference_model.py:88: in <module>
    from petstore_api.models.first_ref import FirstRef
petstore_api/models/first_ref.py:88: in <module>
    from petstore_api.models.second_ref import SecondRef
petstore_api/models/second_ref.py:89: in <module>
    SecondRef.update_forward_refs()
pydantic/main.py:815: in pydantic.main.BaseModel.update_forward_refs
    ???
pydantic/typing.py:554: in pydantic.typing.update_model_forward_refs
    ???
pydantic/typing.py:520: in pydantic.typing.update_field_forward_refs
    ???
pydantic/typing.py:59: in pydantic.typing.evaluate_forwardref
    ???
/opt/circleci/.pyenv/versions/3.7.12/lib/python3.7/typing.py:467: in _evaluate
    eval(self.__forward_code__, globalns, localns),
<string>:1: in <module>
    ???
E   NameError: name 'Dict' is not defined

looks like some fundamental sytnax errors.

can you please take a look?

@fa0311
Copy link
Contributor Author

fa0311 commented Jul 28, 2023

but the tests in CI stills failed

My explanation was insufficient.
We are currently failing CI testing due to several potential bugs.
For this test to succeed, we need to fix #16151.

I have created #16208 which fixes #16151
I merged this fix in my environment and the test succeeded.

Can I review this pull request again after the review and merge of #16208 ?
Or do I need to merge #16208 into this pull request?

@wing328
Copy link
Member

wing328 commented Jul 29, 2023

Thanks for the explanation. I've merged your PR #16208 (and add a test via another PR)

Please merge the latest master into your branch when you've time.

Thank you.

@fa0311
Copy link
Contributor Author

fa0311 commented Jul 29, 2023

Successful test :)

@wing328
Copy link
Member

wing328 commented Jul 29, 2023

@fa0311 nice. will run some tests later tonight.

@wing328
Copy link
Member

wing328 commented Jul 29, 2023

Tested locally and the result is good. will add tests via another PR.

Thanks again for the PR. Have a nice weekend.

@wing328 wing328 merged commit 48ff57b into OpenAPITools:master Jul 29, 2023
12 checks passed
wing328 added a commit that referenced this pull request Jul 29, 2023
wing328 added a commit that referenced this pull request Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] python-nextgen circular refs lead to no imports
2 participants