Repository navigation
Description
Apache Airflow version
main (development)
If "Other Airflow 2 version" selected, which one?
No response
What happened?
In Airflow 2.x, the following DAG used to 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 the following command, without issues:
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 in airflow dags reserialize to be consistent with what happens when we run airflow dag-processor.
Finally, Airflow should not log "Server Error" and error-level messages because a variable was not found.
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
- I agree to follow this project's Code of Conduct
Activity
tatiana commentedon Apr 22, 2025
After speaking to @ashb and @amoghrajesh , I was able to get the DAG to work by capturing
airflow.sdk.exceptions.AirflowRuntimeError:Airflow still logs
[warning ] Server errorand[error ] Variable not found- while applications / DAG authors can often intentionally try to fetch a variable that does not exist:@amoghrajesh agreed logs can be improved.
It is also not clear to me why the behaviour is inconsistent when running
airflow dags reserializeversusairflow dag-processor- I'd expect either for both of them to fail or work with the original DAG.[-]DAG processor unable to parse DAG that retrieves Variable[/-][+]Error & Warning logs when DAG attempts to fetch a Variable that doesn't exist[/+][-]Error & Warning logs when DAG attempts to fetch a Variable that doesn't exist[/-][+]DAG fails to be parsed while trying to fetch a Variable that doesn't exist[/+]Fix Variable not found issue in Airflow 3
Fix Variable not found issue in Airflow 3 (#1684)
kaxil commentedon Apr 24, 2025
@tatiana Curious why not use the following i.e. set a default:
instead of
tatiana commentedon Apr 28, 2025
@kaxil, unfortunately not.
To explain the problem, I created a simple DAG that illustrates the original issue that I found when porting Cosmos to Airflow 3. In the real case, we are not interested in defining a default value for the variable.
The use case we're covering was initially implemented in astronomer/astronomer-cosmos#1014. If the variable exists, we'll leverage it to build the DAG dynamically. Otherwise, we'll compute the DAG topology using other means.
SergeyZ06 commentedon Jul 3, 2025
The same issue I have:
airflow.sdk.exceptions.AirflowRuntimeError: VARIABLE_NOT_FOUNDamoghrajesh commentedon Jul 4, 2025
@SergeyZ06 can you explain what you are trying in your dag?
SergeyZ06 commentedon Jul 4, 2025
@amoghrajesh hello!
I have some variable in my Airflow UI Variables page. And I got this error while trying to access variable value via my Python code:
from airflow.sdk import Variablemy_awesome_variable = Variable.get("MY_AWESOME_VARIABLE")BTW I'm using Airflow 3.0.2
github-actions commentedon Jul 5, 2026
This issue has been automatically marked as stale because it has been open for 365 days without any activity. There has been several Airflow releases since last activity on this issue. Kindly asking to recheck the report against latest Airflow version and let us know if the issue is reproducible. The issue will be closed in next 30 days if no further activity occurs from the issue author.
github-actions commentedon Aug 5, 2026
This issue has been closed because it has not received response from the issue author.