Fix clearTaskInstances returning 500 instead of 422 on invalid body - #70237
Conversation
The ClearTaskInstancesBody validator raised pydantic.ValidationError with a string argument for its invalid-input branches. In Pydantic v2 that constructor call raises TypeError, which the core API has no handler for, so an invalid request body surfaced as 500 Internal Server Error instead of a 422. Raising ValueError lets Pydantic report the problem as a normal 422, matching the sibling PatchTaskInstanceBody validator in the same file.
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
bugraoz93
left a comment
There was a problem hiding this comment.
Thanks for your first PR!
I am wondering whether we could update this on the openapi auto exception generation/doc generation to include ValidationError too, otherwise we need to check each and every similar case as they should also have the same behavior
|
@bugraoz93 Thanks! Quick clarification on the mechanism: passing a plain string to Pydantic's I also checked the tree, and the only other place using this pattern is Would appreciate another look when you get a chance. Thanks again! |
clearTaskInstances returning 500 instead of 422 on invalid body|
@bugraoz93 @ephraimbuddy whenever you have a moment. Kindly review the PR. Thanks! |
|
@pierrejeambrun Thanks for the review. I will raise a follow up PR for core/src/airflow/api_fastapi/core_api/services/public/connections.py |
Backport successfully created: v3-3-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
…invalid body (apache#70237) The ClearTaskInstancesBody validator raised pydantic.ValidationError with a string argument for its invalid-input branches. In Pydantic v2 that constructor call raises TypeError, which the core API has no handler for, so an invalid request body surfaced as 500 Internal Server Error instead of a 422. Raising ValueError lets Pydantic report the problem as a normal 422, matching the sibling PatchTaskInstanceBody validator in the same file. (cherry picked from commit efec6ba) Co-authored-by: SreeramaYeshwanthGowd <yeshwanthgowdsreerama@gmail.com>
…invalid body (apache#70237) The ClearTaskInstancesBody validator raised pydantic.ValidationError with a string argument for its invalid-input branches. In Pydantic v2 that constructor call raises TypeError, which the core API has no handler for, so an invalid request body surfaced as 500 Internal Server Error instead of a 422. Raising ValueError lets Pydantic report the problem as a normal 422, matching the sibling PatchTaskInstanceBody validator in the same file. (cherry picked from commit efec6ba) Co-authored-by: SreeramaYeshwanthGowd <yeshwanthgowdsreerama@gmail.com>
@SreeramaYeshwanthGowd I double checked after posting my suggestion and in |
…apache#70237) The ClearTaskInstancesBody validator raised pydantic.ValidationError with a string argument for its invalid-input branches. In Pydantic v2 that constructor call raises TypeError, which the core API has no handler for, so an invalid request body surfaced as 500 Internal Server Error instead of a 422. Raising ValueError lets Pydantic report the problem as a normal 422, matching the sibling PatchTaskInstanceBody validator in the same file.
…invalid body (#70237) (#71559) The ClearTaskInstancesBody validator raised pydantic.ValidationError with a string argument for its invalid-input branches. In Pydantic v2 that constructor call raises TypeError, which the core API has no handler for, so an invalid request body surfaced as 500 Internal Server Error instead of a 422. Raising ValueError lets Pydantic report the problem as a normal 422, matching the sibling PatchTaskInstanceBody validator in the same file. (cherry picked from commit efec6ba) Co-authored-by: SreeramaYeshwanthGowd <yeshwanthgowdsreerama@gmail.com>
POST /dags/{dag_id}/clearTaskInstancesreturns500instead of422when the request body is invalid. TheClearTaskInstancesBodyvalidator raisedpydantic.ValidationError("..."), which in Pydantic v2 isn't valid and re-raise aTypeError, and the API has no handler for it, so a bad request surfaces as a server error.Raising
ValueErrorlets Pydantic report it as a422, matching the siblingPatchTaskInstanceBodyvalidator in the same file. Added a parametrized test covering each invalid body case.