Skip to content

[PYTHON] generate code based on pydantic v2#16655

Closed
fa0311 wants to merge 15 commits intoOpenAPITools:oshmoun-masterfrom
fa0311:oshmoun-master-2
Closed

[PYTHON] generate code based on pydantic v2#16655
fa0311 wants to merge 15 commits intoOpenAPITools:oshmoun-masterfrom
fa0311:oshmoun-master-2

Conversation

@fa0311
Copy link
Contributor

@fa0311 fa0311 commented Sep 24, 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/configs/*.yaml
    ./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.
  • File the PR against the correct branch: master (upcoming 7.1.0 minor release - breaking changes with fallbacks), 8.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.

"__root__\n"
" DanishPig expected dict not int (type=type_error)")
" Input should be a valid dictionary or instance of BasquePig [type=model_type, input_value=1, input_type=int]\n"
" For further information visit https://errors.pydantic.dev/2.3/v/model_type, 1 validation error for DanishPig\n"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not wise to include the document url in the test
Since pydantic v2.4.0 was released a few hours ago, the URL has changed and the test will fail

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. we didn't take into consideration upgrading pydantic to newer version when writing the test. please feel free to revise the test

{{/vendorExtensions.x-py-postponed-example-imports}}
{{classname}}.update_forward_refs()
try:
{{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}()
Copy link
Contributor Author

@fa0311 fa0311 Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use .model_rebuild(raise_errors=False) instead of try.
However, this is a stopgap measure and in practice should be implemented without using raise_errors.
I spent a lot of time trying to rebuild without raise_errors, but couldn't come up with a good solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove the usePydanticV2 switch the template and the java class as python client generator now only supports pydantic v2.

@jakubno
Copy link

jakubno commented Sep 26, 2023

I didn't use the usePydanticV2 flag 🙈

I've tested it and found following issues:

  • The code doesn't work for models with camel case names:
class Session(BaseModel):
    """
    Session
    """
session_id: StrictStr = Field(
        ..., alias="sessionID", description="Identifier of the session"
    )

then I am receiving following error:

pydantic_core._pydantic_core.ValidationError: 1 validation errors for Session
 sessionID
   Field required [type=missing, input_value={'session_id': 'fce131d5'}, input_type=dict]
     For further information visit https://errors.pydantic.dev/2.4/v/missing
  • parse_obj - is still in some places
  • there's still @validate_arguments in the code:
PydanticDeprecatedSince20: The `validate_arguments` method is deprecated; use `validate_call` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.4/migration/
    @validate_arguments

Python version: 3.11.5
Pydantic: 2.4.0

@fa0311
Copy link
Contributor Author

fa0311 commented Sep 29, 2023

Continue to #16685

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants