Validate update_mask fields in PATCH endpoints against Pydantic models#62657
Open
Vamsi-klu wants to merge 1 commit intoapache:mainfrom
Open
Validate update_mask fields in PATCH endpoints against Pydantic models#62657Vamsi-klu wants to merge 1 commit intoapache:mainfrom
Vamsi-klu wants to merge 1 commit intoapache:mainfrom
Conversation
Contributor
Author
When update_mask is provided, Pydantic validation was skipped entirely, allowing invalid field values to bypass validation and go straight to setattr() on ORM models. Now validation runs regardless of whether update_mask is provided. Affected endpoints: variables, connections, dags, pools. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1acaa21 to
d0fa637
Compare
Contributor
SameerMesiah97
left a comment
There was a problem hiding this comment.
You might need to adjust the approach slightly. Left comments.
|
|
||
| try: | ||
| ConnectionBody(**patch_body.model_dump()) | ||
| ConnectionBody(**patch_body.model_dump(include=fields_to_update)) |
Contributor
There was a problem hiding this comment.
As evidenced bythe CI failures, it looks like you are validating only the subset of fields being updated against the full ConnectionBody model. Since ConnectionBody has required fields (e.g. conn_type), partial patch payloads now fail validation.
I think we may need to retrieve the existing model, merge the patch data, and then validate the merged result instead.
| VariableBody(**patch_body.model_dump()) | ||
| VariableBody(**patch_body.model_dump(include=fields_to_update)) | ||
| except ValidationError as e: | ||
| raise RequestValidationError(errors=e.errors()) |
Contributor
There was a problem hiding this comment.
Above comment applies here as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
update_maskis provided in PATCH endpoints, Pydantic validation was previously skipped entirelysetattr()on ORM modelsupdate_maskis providedCo-contributors : @codingrealitylabs @girlcoder-gaming
Test plan
update_maskand valid data still worksupdate_maskand invalid data now returns 400/422update_maskstill validates correctlypytest tests/api_fastapi/core_api/routes/public/test_variables.py tests/api_fastapi/core_api/routes/public/test_connections.py tests/api_fastapi/core_api/routes/public/test_dags.py tests/api_fastapi/core_api/routes/public/test_pools.py -v🤖 Generated with Claude Code