You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[CLI command only] Importing Variable from airflow.sdk causes an ImportError: cannot import name 'SUPERVISOR_COMMS' for top-level Variable when running airflow dags reserialize #48554
EDIT: this only affects the CLI command airflow dags reserialize, the dag-processor handles the dag fine and it runs correctly.
Apache Airflow version
3.0.0
If "Other Airflow 2 version" selected, which one?
main
What happened?
This dag serializes and runs fine for from airflow.models import Variable but not for from airflow.sdk import Variable
from airflow.sdk import dag, Variable
from airflow.decorators import task
# from airflow.models import Variable
# This one only works for imports from airflow.models, not from airflow.sdk
var1 = Variable.get("v1", "TOP_LEVEL_VAR")
@dag()
def test_var():
@task
def get_var():
print("TOP LEVEL VAR ", var1)
# this one works for both imports, from airflow.sdk and from airflow.models
var2 = Variable.get("v2", "TASK_LEVEL_VAR")
print("TASK LEVEL VAR ", var2)
get_var()
test_var()
The error is only caused when the Variable is used at the top level of the dag, not when within a task.
Error:
Traceback (most recent call last):
File "/opt/airflow/task-sdk/src/airflow/sdk/definitions/variable.py", line 53, in get
return _get_variable(key, deserialize_json=deserialize_json)
File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/context.py", line 185, in _get_variable
from airflow.sdk.execution_time.task_runner import SUPERVISOR_COMMS
ImportError: cannot import name 'SUPERVISOR_COMMS' from 'airflow.sdk.execution_time.task_runner' (/opt/airflow/task-sdk/src/airflow/sdk/execution_time/task_runner.py)
What you think should happen instead?
The dag should serialize and run with the updated import.
How to reproduce
Add the above dag to your env, run airflow dags reserialize, see the error. Switch the import of Variable to airflow.models to see the dag work.
Tried on the latest main and the issue seems to be limited to the airflow dags reseialize command. The dag processor can handle the dag fine. So not the most high priority issue in this case :)
The screenshot below shows the cli command output with the error and having processed the other 3 dags in my env, while the dag processor at the same time is happy to process all 4 dags including the one in this issue
changed the title [-]Importing `Variable` from `airflow.sdk` causes an `ImportError: cannot import name 'SUPERVISOR_COMMS'` when the Variable is used at the top level of the dag[/-][+][CLI command only] Importing `Variable` from `airflow.sdk` causes an `ImportError: cannot import name 'SUPERVISOR_COMMS'` for top-level Variable when running `airflow dags reserialize`[/+]on Mar 31, 2025
Hi @vatsrahul1001 Since this is marked as low priority. Can I try this out and propose a fix, if this is still an issue in latest main ?
You can start from reproducing it and checking it - I don't think anyone will be able to answer your question without attempting to reproduce it. And also even checking and posting here "yep it looks fixed in main" is one of the best contributions you can make.
Reacted by Rahul Vats, Tamara Fingerlin and Prajwal Agarwal
I am able to reproduce it locally with main development branch. However, having some difficulty in understanding how to fix this. As also mentioned above: SUPERVISOR_COMMS is getting initialized only inside the @task get_var method. Any recommendations on how to get started ? Thanks
I am able to reproduce it locally with main development branch. However, having some difficulty in understanding how to fix this. As also mentioned above: SUPERVISOR_COMMS is getting initialized only inside the @task get_var method. Any recommendations on how to get started ? Thanks
Thanks for checking! I will check and add some pointers soon.
I encountered this issue on 3.0.1 when running a test that creates a dagbag. It went away when I stopped using the -n flag for pytest (from pytest-xdist). It seems to me like some race condition or IPC issue involving multiple instances of dagbag (or dag processors). Interestingly, -n 1 exhibits this issue, but -n 0 does not.
I seem to get this error in 3.0.1 as well when using Variable.get("my_variable") inside an external_python task. The variable is perfectly able to be retrieved from an ordinary task. The variable is also listed when executing the airflow variables list command from an python environment activated terminal. The latter suggests, that the virtual environment should be properly set up, in my opinion. This setup worked fine in airflow 2.10.5 (however using from airflow.models import Variable instead of from airflow.sdk import Variable)
I don't know if the cause of this issue is the same, but sounds similar to me.
I faced the same ImportError trying to evaluate LazyXComSequence(<unevaluated length>) in the reduce function during dynamic task mapping. Running with dag.test(), LocalExecutor, Airflow 3.0.1.
# Reduce function@taskdefsend_notifications(data_to_notificate: list[tuple[Rule, ObjectStoragePath]], **context) ->None:
forrule, input_fileindata_to_notificate: # The error raises here
...
UPD: the same parameter is identified as LazySelectSequence([4 items]) in Airflow 2.11.0, and the DAG works properly.
Seconding the dag.test() note - I am able to replicate the same error trying to use Connection.get (similar to Variable.get in initial example) and running via dag.test() (apologies for non-task flow syntax)
from airflow.models.dag import DAG
from airflow.providers.standard.operators.python import PythonOperator
from airflow.sdk.definitions.connection import Connection
MSSQL_CONN_ID = "test_conn_id"
with DAG(
dag_id="test_dag",
catchup=False,
) as dag:
PythonOperator(
task_id = "foo",
python_callable=Connection.get,
op_args=[MSSQL_CONN_ID]
)
if __name__ == "__main__":
dag.test()
Running this DAG via dag.test() results in this error, running normally (via UI) is fine.
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.
Activity
vatsrahul1001 commentedon Mar 31, 2025
@TJaniF I tried it on main and it works well. Can you try on latest main ?
TJaniF commentedon Mar 31, 2025
Tried on the latest main and the issue seems to be limited to the
airflow dags reseializecommand. The dag processor can handle the dag fine. So not the most high priority issue in this case :)The screenshot below shows the cli command output with the error and having processed the other 3 dags in my env, while the dag processor at the same time is happy to process all 4 dags including the one in this issue
[-]Importing `Variable` from `airflow.sdk` causes an `ImportError: cannot import name 'SUPERVISOR_COMMS'` when the Variable is used at the top level of the dag[/-][+][CLI command only] Importing `Variable` from `airflow.sdk` causes an `ImportError: cannot import name 'SUPERVISOR_COMMS'` for top-level Variable when running `airflow dags reserialize`[/+]Prajwal7842 commentedon Apr 1, 2025
Hi @vatsrahul1001 Since this is marked as low priority. Can I try this out and propose a fix, if this is still an issue in latest main ?
potiuk commentedon Apr 1, 2025
You can start from reproducing it and checking it - I don't think anyone will be able to answer your question without attempting to reproduce it. And also even checking and posting here "yep it looks fixed in main" is one of the best contributions you can make.
2 remaining items
Prajwal7842 commentedon Apr 5, 2025
I am able to reproduce it locally with main development branch. However, having some difficulty in understanding how to fix this. As also mentioned above: SUPERVISOR_COMMS is getting initialized only inside the @task get_var method. Any recommendations on how to get started ? Thanks
bugraoz93 commentedon Apr 5, 2025
Thanks for checking! I will check and add some pointers soon.
Dev-iL commentedon May 21, 2025
I encountered this issue on 3.0.1 when running a test that creates a dagbag. It went away when I stopped using the
-nflag for pytest (from pytest-xdist). It seems to me like some race condition or IPC issue involving multiple instances of dagbag (or dag processors). Interestingly,-n 1exhibits this issue, but-n 0does not.fromm1990 commentedon May 23, 2025
I seem to get this error in 3.0.1 as well when using
Variable.get("my_variable")inside an external_python task. The variable is perfectly able to be retrieved from an ordinary task. The variable is also listed when executing theairflow variables listcommand from an python environment activated terminal. The latter suggests, that the virtual environment should be properly set up, in my opinion. This setup worked fine in airflow 2.10.5 (however usingfrom airflow.models import Variableinstead offrom airflow.sdk import Variable)I don't know if the cause of this issue is the same, but sounds similar to me.
opeida commentedon May 29, 2025
I faced the same ImportError trying to evaluate
LazyXComSequence(<unevaluated length>)in the reduce function during dynamic task mapping. Running withdag.test(), LocalExecutor, Airflow 3.0.1.UPD: the same parameter is identified as
LazySelectSequence([4 items])in Airflow 2.11.0, and the DAG works properly.jablecherman commentedon May 29, 2025
@opeida
Seconding the
dag.test()note - I am able to replicate the same error trying to useConnection.get(similar toVariable.getin initial example) and running viadag.test()(apologies for non-task flow syntax)Running this DAG via
dag.test()results in this error, running normally (via UI) is fine.farkmarnum commentedon Jun 6, 2025
We're seeing this same error when running tests (pytest):
The seconds test fails with:
Both on Airflow 3.0.1 and 3.0.2rc2.
alkismavridis commentedon Jun 25, 2025
Any news one that? We heavily use
airflow dags reserialzeand this error has significantly affected our workflow.dshvedchenko commentedon Aug 13, 2025
faced this issue in tests, when forget to update mock to
airflow.sdk.Variables.getfromairflow.models.Variables.getPrajwal7842 commentedon Oct 18, 2025
I think the original issue in the thread is fixed. I am unable to reproduce this on latest main with airflow dags reserialize command. SS attached.
[
](url)
github-actions commentedon Oct 19, 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.