Skip to content

Validate update_mask fields in PATCH endpoints against Pydantic models#62657

Open
Vamsi-klu wants to merge 1 commit intoapache:mainfrom
Vamsi-klu:fix/m2-patch-endpoints-validate-update-mask
Open

Validate update_mask fields in PATCH endpoints against Pydantic models#62657
Vamsi-klu wants to merge 1 commit intoapache:mainfrom
Vamsi-klu:fix/m2-patch-endpoints-validate-update-mask

Conversation

@Vamsi-klu
Copy link
Contributor

@Vamsi-klu Vamsi-klu commented Mar 1, 2026

Summary

  • When update_mask is provided in PATCH endpoints, Pydantic validation was previously skipped entirely
  • Invalid field values could bypass validation and go straight to setattr() on ORM models
  • Now validation runs on the subset of fields being updated regardless of whether update_mask is provided
  • Affected endpoints: variables, connections, dags, pools

Co-contributors : @codingrealitylabs @girlcoder-gaming

Test plan

  • Verify PATCH with valid update_mask and valid data still works
  • Verify PATCH with update_mask and invalid data now returns 400/422
  • Verify PATCH without update_mask still validates correctly
  • Run pytest 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

@Vamsi-klu Vamsi-klu marked this pull request as ready for review March 1, 2026 07:35
@Vamsi-klu
Copy link
Contributor Author

cc @vincbeck @kaxil — Would appreciate your review. This ensures Pydantic validation runs on PATCH endpoint fields even when update_mask is provided, preventing invalid values from bypassing validation via setattr().

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>
Copy link
Contributor

@SameerMesiah97 SameerMesiah97 left a comment

Choose a reason for hiding this comment

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

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))
Copy link
Contributor

Choose a reason for hiding this comment

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

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())
Copy link
Contributor

Choose a reason for hiding this comment

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

Above comment applies here as well.

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.

2 participants