This is an automated email from the ASF dual-hosted git repository.
vincbeck pushed a commit to branch v3-3-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-3-test by this push:
new 3610b802eec [v3-3-test] Remove the unreachable 404 from the create
Variable endpoint (#71245) (#72190)
3610b802eec is described below
commit 3610b802eec49c583991eebe4c707e6acab7f393
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Aug 28 08:47:19 2026 -0400
[v3-3-test] Remove the unreachable 404 from the create Variable endpoint
(#71245) (#72190)
The branch guards a read-back of the row Variable.set() upserted moments
earlier
through the same session, so it cannot be reached. It exists only to narrow
a type:
SQLAlchemy 2 declares Session.scalar() as returning Optional, and a raise
is what
convinces mypy the value is not None.
Paying for that with an HTTP status is the problem. A 404 on a create
endpoint tells
a caller the variable they just created was not found, which left the
endpoint
choosing between publishing a response it can never return and leaving its
spec
incomplete. Asking the session for exactly one row states the same
invariant where
it belongs — in the query — so neither control flow nor a status code is
needed to
express it.
(cherry picked from commit 6171e2bf9922f21db4729062356eb28963bec978)
Co-authored-by: Jyun-An Chen <[email protected]>
---
.../src/airflow/api_fastapi/core_api/routes/public/variables.py | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git
a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py
b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py
index e48031cd68d..ab753437614 100644
--- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py
+++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py
@@ -183,14 +183,7 @@ def post_variable(
Variable.set(**post_body.model_dump(), session=session)
- variable = session.scalar(select(Variable).where(Variable.key ==
post_body.key).limit(1))
- if variable is None:
- raise HTTPException(
- status.HTTP_404_NOT_FOUND,
- f"Variable with key: `{post_body.key}` was not found",
- )
-
- return variable
+ return session.scalars(select(Variable).where(Variable.key ==
post_body.key)).one()
@variables_router.patch(