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

Update deprecated Pydantic v2 methods #2213

Open
cruisen opened this issue Dec 9, 2024 · 3 comments
Open

Update deprecated Pydantic v2 methods #2213

cruisen opened this issue Dec 9, 2024 · 3 comments
Labels
answered enhancement New feature or request help wanted Extra attention is needed

Comments

@cruisen
Copy link

cruisen commented Dec 9, 2024

The package currently uses several deprecated Pydantic v2 methods that should be updated to their new equivalents:

  1. parse_obj -> model_validate
  2. dict -> model_dump
  3. __fields_set__ -> model_fields_set

These deprecation warnings appear when using the package with Pydantic v2:

  • PydanticDeprecatedSince20: The parse_obj method is deprecated; use model_validate instead.
  • PydanticDeprecatedSince20: The dict method is deprecated; use model_dump instead.
  • PydanticDeprecatedSince20: The fields_set attribute is deprecated, use model_fields_set instead

These methods will be removed in Pydantic v3.0, so they should be updated to ensure future compatibility.

Relevant files:

  • datamodel_code_generator/parser/jsonschema.py

See the Pydantic V2 Migration Guide for more details on the changes.

@riferg206
Copy link

@koxudaxi The unit tests for datamodel_code_generator/parser/jsonschema.py also throw deprecation warnings for the same reasons as above. Should these be updated as well or do they need to stay for backwards compatibility with Pydantic V1?

@koxudaxi
Copy link
Owner

Yes, this implementation is designed to support both v1 and v2. For backward compatibility reasons, we need to maintain support for both versions.
If this is causing issues for users, we could completely suppress these warnings. Would that be a better approach from a user perspective?

@koxudaxi koxudaxi added help wanted Extra attention is needed answered labels Jan 13, 2025
@riferg206
Copy link

We should be able to avoid suppressing warnings, which is preferable as both maintainer and user IMO. The deprecation warnings will still get thrown when the unit tests are run, but that may be unavoidable without adding version handling in the unit tests themselves. What is preferable from a maintainers standpoint? I'm new to open source, but if this seems sensible I can open a new PR with the changes from the one I closed and request to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants