andreahlert commented on code in PR #61630:
URL: https://github.com/apache/airflow/pull/61630#discussion_r3295879015
##########
task-sdk/src/airflow/sdk/execution_time/context.py:
##########
@@ -291,9 +291,26 @@ def _get_variable(key: str, deserialize_json: bool) -> Any:
)
# If no backend found the variable, raise a not found error (mirrors
_get_connection)
- from airflow.sdk.exceptions import AirflowRuntimeError, ErrorType
+ from airflow.sdk.execution_time import task_runner
from airflow.sdk.execution_time.comms import ErrorResponse
+ if not hasattr(task_runner, "SUPERVISOR_COMMS"):
+ raise AirflowRuntimeError(
+ ErrorResponse(
+ error=ErrorType.VARIABLE_NOT_FOUND,
+ detail={
+ "message": (
+ f"Variable '{key}' not found. Note: SUPERVISOR_COMMS
is not available, "
+ "which means this code is running outside a task
execution context "
+ "(e.g., at the top level of a DAG file). "
+ "Consider using environment variables
(AIRFLOW_VAR_<key>), "
+ "Jinja templates ({{ var.value.<key> }}), "
+ "or move the Variable.get() call inside a task
function."
+ )
+ },
+ )
+ )
+
raise AirflowRuntimeError(
ErrorResponse(error=ErrorType.VARIABLE_NOT_FOUND, detail={"message":
f"Variable {key} not found"})
)
Review Comment:
Good catch, that one slipped through. Fixed.
--
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]