1fanwang opened a new pull request, #72926: URL: https://github.com/apache/airflow/pull/72926
When a task instance had no associated DagRun in the database, updating an existing task state key caused the metastore backend to raise an unhandled ValueError. This escaped to the application handler and returned an HTTP 500 error instead of a missing resource response. This change catches ValueError in patch_task_state_store and returns a 404 Not Found error, matching the error handling in the sibling set endpoint. # Testing Done Reproduction before fix: ```bash uv run --project airflow-core pytest airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_state_store.py -k test_patch_nonexistent_dag_run_returns_404 ``` Pre-fix output: ```text FAILED test_task_state_store.py test_patch_nonexistent_dag_run_returns_404 - ValueError: No DagRun found for dag_id='dag' run_id='nonexistent_run' ``` Verification after fix: ```bash uv run --project airflow-core pytest airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_state_store.py -k "test_patch_nonexistent_dag_run or test_set_nonexistent_dag_run" ``` Post-fix output: ```text ================= 2 passed, 95 deselected, 2 warnings in 4.42s ================= ``` <details> <summary>Raw logs</summary> ```text test_task_state_store.py test_set_nonexistent_dag_run_returns_404 PASSED [ 50%] test_task_state_store.py test_patch_nonexistent_dag_run_returns_404 PASSED [100%] ``` </details> -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
