You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "dkranchii (via GitHub)" <gi...@apache.org> on 2026/05/24 22:02:52 UTC
[PR] API: Return 400 instead of 500 from materialize_asset on invalid input [airflow]
dkranchii opened a new pull request, #67445:
URL: https://github.com/apache/airflow/pull/67445
The `POST /assets/{asset_id}/materialize` endpoint passed user input (`dag_run_id`, `logical_date` / `data_interval` pairing, `partition_key`) straight through to `MaterializeAssetBody.validate_context()` and `dag.create_dagrun()`. Those raise `ValueError` / `ParamValidationError` on invalid input — e.g. `dag_run_id` containing `..` (path-traversal guard in `DagRun.validate_run_id`), `logical_date` set with no `data_interval`, or a `partition_key` of 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_dagrun` calls in a `try/except (ParamValidationError, ValueError)` and re-raises as `HTTPException(400)` with the validator's message in the `detail`. Mirrors the established pattern in the sibling endpoint `airflow.api_fastapi.core_api.routes.public.dag_run.trigger_dag_run`.
### Reproduction (before)
POST /assets/1/materialize
{"dag_run_id": "bad..id"}
→ 500 Internal Server Error
### After
POST /assets/1/materialize
{"dag_run_id": "bad..id"}
→ 400 Bad Request
{"detail": "The run_id 'bad..id' must not contain '..' to prevent path traversal"}
### Tests
Adds `TestPostAssetMaterialize::test_should_respond_400_on_invalid_dag_run_id` asserting the endpoint returns 400 with the validator's message. The test fails (returns 500) on the unpatched code.
### Related
- `AGENTS.md` rule added in #67221: *"Translate domain-layer exceptions to HTTPException at FastAPI route boundaries."*
- Sibling pattern: `airflow.api_fastapi.core_api.routes.public.dag_run.trigger_dag_run`.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — (Cursor) used to test the gap
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] API: Return 400 instead of 500 from materialize_asset on invalid input [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 merged PR #67445:
URL: https://github.com/apache/airflow/pull/67445
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] API: Return 400 instead of 500 from materialize_asset on invalid input [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on PR #67445:
URL: https://github.com/apache/airflow/pull/67445#issuecomment-4540258446
Manual backport: https://github.com/apache/airflow/pull/67526
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] API: Return 400 instead of 500 from materialize_asset on invalid input [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #67445:
URL: https://github.com/apache/airflow/pull/67445#issuecomment-4540158584
### Backport failed to create: v3-2-test. View the failure log <a href='https://github.com/apache/airflow/actions/runs/26432883100'> Run details </a>
Note: As of [Merging PRs targeted for Airflow 3.X](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#merging-prs-targeted-for-airflow-3x)
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.
In matter of doubt please ask in [#release-management](https://apache-airflow.slack.com/archives/C03G9H97MM2) Slack channel.
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>❌</td>
<td>v3-2-test</td>
<td><a href="https://github.com/apache/airflow/commit/0120ba7fd5be8b6d5e7e4184209fb0479127f2d8"><img src='https://img.shields.io/badge/Commit-0120ba7-red' alt='Commit Link'></a></td>
</tr>
</table>
You can attempt to backport this manually by running:
```bash
cherry_picker 0120ba7 v3-2-test
```
This should apply the commit to the v3-2-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.
After you have resolved the conflicts, you can continue the backport process by running:
```bash
cherry_picker --continue
```
If you don't have cherry-picker installed, see the [installation guide](https://github.com/apache/airflow/blob/main/dev/README.md#how-to-backport-pr-with-cherry-picker-cli).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org