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 705880c4898a6..b481db00ea5e6 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 @@ -174,14 +174,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(