-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
python(pydantic): Use validate_by_name config; populate_by_name will be deprecated #22931
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
base: master
Are you sure you want to change the base?
python(pydantic): Use validate_by_name config; populate_by_name will be deprecated #22931
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 issues found across 407 files
Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="modules/openapi-generator/src/main/resources/python/requirements.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/python/requirements.mustache:19">
P2: Dependency version mismatch: requirements.mustache now enforces pydantic >=2.11, but pyproject.mustache (non-poetry1 dependencies) still allows pydantic >=2. This can generate projects that install pydantic <2.11, inconsistent with the new validate_by_name requirement.</violation>
</file>
<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py">
<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py:51">
P2: New `validate_by_name`/`validate_by_alias` config requires Pydantic 2.11+, but `pyproject.toml` still allows `pydantic>=2`, so users can install 2.10 and hit runtime errors when importing this model.</violation>
</file>
<file name="samples/client/echo_api/python/openapi_client/models/category.py">
<violation number="1" location="samples/client/echo_api/python/openapi_client/models/category.py:35">
P2: validate_by_name/validate_by_alias require Pydantic >=2.11, but the sample’s pyproject allows >=2 and poetry.lock pins 2.9.2. Poetry installs can use an older Pydantic that doesn’t support these config keys, breaking alias validation. Update the dependency constraints/lock to >=2.11.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| pycryptodome >= 3.9.0 | ||
| {{/hasHttpSignatureMethods}} | ||
| pydantic >= 2 | ||
| pydantic >= 2.11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Dependency version mismatch: requirements.mustache now enforces pydantic >=2.11, but pyproject.mustache (non-poetry1 dependencies) still allows pydantic >=2. This can generate projects that install pydantic <2.11, inconsistent with the new validate_by_name requirement.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/python/requirements.mustache, line 19:
<comment>Dependency version mismatch: requirements.mustache now enforces pydantic >=2.11, but pyproject.mustache (non-poetry1 dependencies) still allows pydantic >=2. This can generate projects that install pydantic <2.11, inconsistent with the new validate_by_name requirement.</comment>
<file context>
@@ -16,7 +16,7 @@ tornado = ">= 4.2, < 5"
pycryptodome >= 3.9.0
{{/hasHttpSignatureMethods}}
-pydantic >= 2
+pydantic >= 2.11
typing-extensions >= 4.7.1
{{#lazyImports}}
</file context>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timonrieger can you please take a look at this feedback, which seems valid to me?
|
|
||
| model_config = ConfigDict( | ||
| populate_by_name=True, | ||
| validate_by_name=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: New validate_by_name/validate_by_alias config requires Pydantic 2.11+, but pyproject.toml still allows pydantic>=2, so users can install 2.10 and hit runtime errors when importing this model.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py, line 51:
<comment>New `validate_by_name`/`validate_by_alias` config requires Pydantic 2.11+, but `pyproject.toml` still allows `pydantic>=2`, so users can install 2.10 and hit runtime errors when importing this model.</comment>
<file context>
@@ -48,7 +48,8 @@ def status_validate_enum(cls, value):
model_config = ConfigDict(
- populate_by_name=True,
+ validate_by_name=True,
+ validate_by_alias=True,
validate_assignment=True,
</file context>
|
|
||
| model_config = ConfigDict( | ||
| populate_by_name=True, | ||
| validate_by_name=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: validate_by_name/validate_by_alias require Pydantic >=2.11, but the sample’s pyproject allows >=2 and poetry.lock pins 2.9.2. Poetry installs can use an older Pydantic that doesn’t support these config keys, breaking alias validation. Update the dependency constraints/lock to >=2.11.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/python/openapi_client/models/category.py, line 35:
<comment>validate_by_name/validate_by_alias require Pydantic >=2.11, but the sample’s pyproject allows >=2 and poetry.lock pins 2.9.2. Poetry installs can use an older Pydantic that doesn’t support these config keys, breaking alias validation. Update the dependency constraints/lock to >=2.11.</comment>
<file context>
@@ -32,7 +32,8 @@ class Category(BaseModel):
model_config = ConfigDict(
- populate_by_name=True,
+ validate_by_name=True,
+ validate_by_alias=True,
validate_assignment=True,
</file context>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6 issues found across 13 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="samples/server/petstore/python-fastapi/src/openapi_server/models/api_response.py">
<violation number="1">
P2: `populate_by_name` is deprecated in Pydantic v2.11+; this change removes `validate_by_name`/`validate_by_alias` and can trigger deprecation warnings or future incompatibility. Use the new config keys instead.</violation>
</file>
<file name="samples/server/petstore/python-fastapi/src/openapi_server/models/category.py">
<violation number="1">
P2: `populate_by_name` is deprecated in Pydantic 2.11+. Replacing `validate_by_name`/`validate_by_alias` with `populate_by_name` will emit deprecation warnings now and break in v3. Use the new config keys instead to avoid future incompatibility.</violation>
</file>
<file name="samples/server/petstore/python-fastapi/src/openapi_server/models/tag.py">
<violation number="1">
P2: `populate_by_name` is deprecated in Pydantic 2.11+ and replaced by `validate_by_name`/`validate_by_alias`. Reintroducing it can emit deprecation warnings and diverges from the recommended config.</violation>
</file>
<file name="samples/server/petstore/python-fastapi/src/openapi_server/models/pet.py">
<violation number="1">
P2: Model config uses deprecated `populate_by_name` instead of `validate_by_name`/`validate_by_alias`, which will trigger deprecation warnings in Pydantic v2.11+ and conflicts with the PR goal of moving to the new config settings.</violation>
</file>
<file name="samples/server/petstore/python-fastapi/src/openapi_server/models/user.py">
<violation number="1">
P2: Using `populate_by_name` is deprecated in Pydantic 2.11+ and will be removed in v3, which will emit warnings and hurt forward compatibility. Prefer `validate_by_name`/`validate_by_alias` instead.</violation>
</file>
<file name="samples/server/petstore/python-fastapi/src/openapi_server/models/order.py">
<violation number="1">
P2: `populate_by_name` is deprecated in Pydantic >=2.11 and will be removed in v3; this reintroduces a deprecated setting instead of `validate_by_name`/`validate_by_alias`, causing deprecation warnings and future breakage.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
see https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.populate_by_name, requires pydantic 2.11.
keeping as draft for now since this pydantic version restriction might be to limitingEDIT: pydantic v2.11 was released ~1 year ago
PR checklist
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*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Switch Python model templates to Pydantic’s validate_by_name/validate_by_alias (replacing deprecated populate_by_name) and raise the minimum Pydantic version to 2.11. FastAPI generator remains unchanged.
Dependencies
Migration
Written for commit 6460f34. Summary will update on new commits.