This is an automated email from the ASF dual-hosted git repository.

henry3260 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 76bf88a4877 API: Translate domain ValueError in Task State Store route 
(#73753)
76bf88a4877 is described below

commit 76bf88a4877358a1a648bd05d45811f1c7c5e5ab
Author: Vardhman Gupta <[email protected]>
AuthorDate: Wed Sep 30 12:41:56 2026 +0530

    API: Translate domain ValueError in Task State Store route (#73753)
---
 .../api_fastapi/core_api/routes/public/task_state_store.py |  7 ++++++-
 .../core_api/routes/public/test_task_state_store.py        | 14 ++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git 
a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_state_store.py
 
b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_state_store.py
index 0d844b8b3ac..8c0e5be5ef3 100644
--- 
a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_state_store.py
+++ 
b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_state_store.py
@@ -267,7 +267,12 @@ def patch_task_state_store(
             detail=f"Task state store key {key!r} not found",
         )
 
-    _get_db_backend().set(scope, key, json.dumps(body.value), 
expires_at=existing.expires_at, session=session)
+    try:
+        _get_db_backend().set(
+            scope, key, json.dumps(body.value), 
expires_at=existing.expires_at, session=session
+        )
+    except ValueError as e:
+        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, 
detail=str(e)) from e
 
 
 @task_state_store_router.delete(
diff --git 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_state_store.py
 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_state_store.py
index 1fe16ec45b6..95f3285542c 100644
--- 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_state_store.py
+++ 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_state_store.py
@@ -394,6 +394,20 @@ class TestPatchTaskState(TestTaskStateEndpoint):
         self._session.refresh(row)
         assert row.value == expected_db
 
+    def test_patch_task_state_store_domain_error_returns_404(self, 
test_client):
+        """Domain-level ValueError raised during PATCH translates to HTTP 
404."""
+        _create_task_state_store_row(self._session, "job_id", "initial", 
self.dag_run)
+        self._session.commit()
+
+        with patch(
+            "airflow.state.metastore.MetastoreBackend.set",
+            autospec=True,
+            side_effect=ValueError(f"No DagRun found for dag_id={DAG_ID!r} 
run_id={RUN_ID!r}"),
+        ):
+            response = test_client.patch(f"{BASE_URL}/job_id", json={"value": 
"v2"})
+            assert response.status_code == 404
+            assert response.json()["detail"] == f"No DagRun found for 
dag_id={DAG_ID!r} run_id={RUN_ID!r}"
+
     def test_unauthorized_returns_401(self, unauthenticated_test_client):
         assert unauthenticated_test_client.patch(f"{BASE_URL}/job_id", 
json={"value": "v"}).status_code == 401
 

Reply via email to