tatiana opened a new issue, #49543:
URL: https://github.com/apache/airflow/issues/49543
### Apache Airflow version
main (development)
### If "Other Airflow 2 version" selected, which one?
_No response_
### What happened?
In Airflow 2.x, the following DAG would work (when specifying other
mandatory fields):
```
import json
from airflow import DAG
from airflow.operators.empty import EmptyOperator
from airflow.models import Variable
try:
variable_value = Variable.get("some-variable", deserialize_json=True)
except (json.decoder.JSONDecodeError, KeyError):
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
```
In Airflow 3 (commit `dda86263e8a9c171d91729f14668028408568022`), if we try
to parse it using:
```
airflow dag-processor
```
It fails and logs:
```
================================================================================
DAG File Processing Stats
Bundle File Path PID Current Duration #
DAGs # Errors Last Duration Last Run At
----------- ------------------------------ ----- ------------------
-------- ---------- --------------- -------------------
dags-folder example_dag_variable_access.py
0 1 0.62s 2025-04-22T11:02:54
================================================================================
[2025-04-22T12:03:25.160+0100] {manager.py:523} INFO - Not time to refresh
bundle dags-folder
[2025-04-22T12:03:25.338+0100] {_client.py:1025} INFO - HTTP Request: GET
http://in-process.invalid./variables/some-variable "HTTP/1.1 404 Not Found"
2025-04-22 12:03:25 [warning ] Server error
[airflow.sdk.api.client] detail={'detail': {'reason': 'not_found', 'message':
"Variable with key 'some-variable' not found"}}
2025-04-22 12:03:25 [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
```
Changing the DAG to capture `ServerResponseError` doesn't work either, and I
observe the same issue:
```
import json
from airflow import DAG
from airflow.operators.empty import EmptyOperator
from airflow.models import Variable
from airflow.sdk.api.client import ServerResponseError
try:
variable_value = Variable.get("some-variable", deserialize_json=True)
except (json.decoder.JSONDecodeError, KeyError, ServerResponseError):
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
```
It is interesting that the DAG can be serialized if I run
```
airflow dags reserialize
```
### What you think should happen instead?
Airflow should continue to allow DAGS to retrieve Variables and allow DAG
authors to capture the exception if a variable does not exist, without raising
errors during DAG parsing and failing to render the DAG.
I'd expect the behaviour seen i `airflow dags reserialize` to be consistent
with what happens when we run `airflow dag-processor`.
### How to reproduce
Described previously
### Operating System
Tested in MacOS 15.4
### Versions of Apache Airflow Providers
N/A
### Deployment
Other
### Deployment details
_No response_
### Anything else?
_No response_
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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]