Uh oh!
There was an error while loading. Please reload this page.
API: Return 400 instead of 500 from materialize_asset on invalid input - #67445
Conversation
…idation input The materialize_asset POST endpoint passed user input (dag_run_id, logical_date/data_interval pairing, partition_key) straight through to MaterializeAssetBody.validate_context() and dag.create_dagrun(), which raise ValueError / ParamValidationError on invalid input (e.g. dag_run_id containing '..', invalid partition_key type, logical_date/data_interval mismatch). Those exceptions escaped uncaught and were returned as 500 Internal Server Error, even though the route's OpenAPI spec already documents 400 for this case. Wrap the validate_context / create_dagrun calls in try/except and re-raise as HTTPException(400) with the validator's message in the detail, matching the sibling pattern in dag_run.trigger_dag_run. Regression test asserts dag_run_id='bad..id' returns 400, not 500.
4461546 to
3353f9dCompareThere was a problem hiding this comment.
Nice!
Nice to see the #67221 agent rule did catch the violation.
Backport failed to create: v3-2-test. View the failure log Run detailsNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
You can attempt to backport this manually by running: cherry_picker 0120ba7 v3-2-testThis should apply the commit to the v3-2-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf you don't have cherry-picker installed, see the installation guide. |
jason810496
commented
May 26, 2026
Manual backport: #67526 |
… invalid validation input (apache#67445) The materialize_asset POST endpoint passed user input (dag_run_id, logical_date/data_interval pairing, partition_key) straight through to MaterializeAssetBody.validate_context() and dag.create_dagrun(), which raise ValueError / ParamValidationError on invalid input (e.g. dag_run_id containing '..', invalid partition_key type, logical_date/data_interval mismatch). Those exceptions escaped uncaught and were returned as 500 Internal Server Error, even though the route's OpenAPI spec already documents 400 for this case. Wrap the validate_context / create_dagrun calls in try/except and re-raise as HTTPException(400) with the validator's message in the detail, matching the sibling pattern in dag_run.trigger_dag_run. Regression test asserts dag_run_id='bad..id' returns 400, not 500. (cherry picked from commit 0120ba7) Co-authored-by: Deepak kumar <deepakkumar@meta.com>
… invalid validation input (#67445) (#67526) The materialize_asset POST endpoint passed user input (dag_run_id, logical_date/data_interval pairing, partition_key) straight through to MaterializeAssetBody.validate_context() and dag.create_dagrun(), which raise ValueError / ParamValidationError on invalid input (e.g. dag_run_id containing '..', invalid partition_key type, logical_date/data_interval mismatch). Those exceptions escaped uncaught and were returned as 500 Internal Server Error, even though the route's OpenAPI spec already documents 400 for this case. Wrap the validate_context / create_dagrun calls in try/except and re-raise as HTTPException(400) with the validator's message in the detail, matching the sibling pattern in dag_run.trigger_dag_run. Regression test asserts dag_run_id='bad..id' returns 400, not 500. (cherry picked from commit 0120ba7) Co-authored-by: Deepak kumar <deepakkumar@meta.com>
… invalid validation input (#67445) (#67526) The materialize_asset POST endpoint passed user input (dag_run_id, logical_date/data_interval pairing, partition_key) straight through to MaterializeAssetBody.validate_context() and dag.create_dagrun(), which raise ValueError / ParamValidationError on invalid input (e.g. dag_run_id containing '..', invalid partition_key type, logical_date/data_interval mismatch). Those exceptions escaped uncaught and were returned as 500 Internal Server Error, even though the route's OpenAPI spec already documents 400 for this case. Wrap the validate_context / create_dagrun calls in try/except and re-raise as HTTPException(400) with the validator's message in the detail, matching the sibling pattern in dag_run.trigger_dag_run. Regression test asserts dag_run_id='bad..id' returns 400, not 500. (cherry picked from commit 0120ba7) Co-authored-by: Deepak kumar <deepakkumar@meta.com>
The
POST /assets/{asset_id}/materializeendpoint passed user input (dag_run_id,logical_date/data_intervalpairing,partition_key) straight through toMaterializeAssetBody.validate_context()anddag.create_dagrun(). Those raiseValueError/ParamValidationErroron invalid input — e.g.dag_run_idcontaining..(path-traversal guard inDagRun.validate_run_id),logical_dateset with nodata_interval, or apartition_keyof the wrong type. The exceptions escaped uncaught and were returned as 500 Internal Server Error, even though the route's OpenAPI spec already documents 400 for this case.This wraps the
validate_context/create_dagruncalls in atry/except (ParamValidationError, ValueError)and re-raises asHTTPException(400)with the validator's message in thedetail. Mirrors the established pattern in the sibling endpointairflow.api_fastapi.core_api.routes.public.dag_run.trigger_dag_run.Reproduction (before)
After
Tests
Adds
TestPostAssetMaterialize::test_should_respond_400_on_invalid_dag_run_idasserting the endpoint returns 400 with the validator's message. The test fails (returns 500) on the unpatched code.Related
AGENTS.mdrule added in AGENTS.md: require translating domain-layer exceptions toHTTPExceptionat FastAPI route boundaries #67221: "Translate domain-layer exceptions to HTTPException at FastAPI route boundaries."airflow.api_fastapi.core_api.routes.public.dag_run.trigger_dag_run.Was generative AI tooling used to co-author this PR?