tatiana commented on issue #49543:
URL: https://github.com/apache/airflow/issues/49543#issuecomment-2821037202
After speaking to @ashb and @amoghrajesh , I was able to get the DAG to work
by capturing `airflow.sdk.exceptions.AirflowRuntimeError`:
```
import json
from airflow import DAG
from airflow.operators.empty import EmptyOperator
from airflow.models import Variable
from airflow.sdk.exceptions import AirflowRuntimeError
try:
variable_value = Variable.get("some-variable", deserialize_json=True)
except (json.decoder.JSONDecodeError, KeyError, AirflowRuntimeError):
variable_value = {"task_id": "default_task_name"}
with DAG(dag_id="example_dag_variable_access") as dag:
task_from_var = EmptyOperator(task_id=variable_value.get("task_id"))
task_from_var
```
Airflow still logs `[warning ] Server error` and `[error ] Variable not
found` - while applications / DAG authors can often intentionally try to fetch
a variable that does not exist:
```
dag-processor | 2025-04-22 12:25:50 [warning ] Server error
[airflow.sdk.api.client] detail={'detail': {'reason': 'not_found', 'message':
"Variable with key 'some-variable' not found"}}
dag-processor | 2025-04-22 12:25:50 [error ] Variable not found
[airflow.sdk.api.client] detail={'detail': {'reason': 'not_found', 'message':
"Variable with key 'some-variable' not found"}} key=some-variable
status_code=404
```
@amoghrajesh agreed logs can be improved
--
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]