Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a variable in Dag is failing due to 'Direct database access via the ORM is not allowed in Airflow 3.0' #47920

Open
1 of 2 tasks
atul-astronomer opened this issue Mar 18, 2025 · 3 comments · May be fixed by #48177
Open
1 of 2 tasks
Assignees
Labels
affected_version:3.0.0beta For all 3.0.0 beta releases area:core kind:bug This is a clearly a bug priority:medium Bug that should be fixed before next release but would not block a release

Comments

@atul-astronomer
Copy link

Apache Airflow version

3.0.0

If "Other Airflow 2 version" selected, which one?

No response

What happened?

Setting a variable in Dag is failing due to 'Direct database access via the ORM is not allowed in Airflow 3.0'

Image

What you think should happen instead?

No response

How to reproduce

Have the below dag in dags folder, you will get import error.

from datetime import datetime

from airflow.providers.standard.operators.bash import BashOperator
from airflow.models import Variable

from airflow import DAG

my_var = Variable.set("param_variable", 10)

dag = DAG(
    'test_api_dag',
    start_date=datetime(2025, 3, 1, 3, 28, 0),
    # # schedule=timedelta(days=1),
    schedule='@daily',
    is_paused_upon_creation=False
)

hello_task = BashOperator(
    task_id='test_task',
    bash_command='echo "Hello World from Airflow!"',
    do_xcom_push = True,
    dag=dag,
)

hello_task

Operating System

Linux

Versions of Apache Airflow Providers

No response

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

@atul-astronomer atul-astronomer added area:core kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet labels Mar 18, 2025
@vatsrahul1001 vatsrahul1001 added priority:medium Bug that should be fixed before next release but would not block a release affected_version:3.0.0beta For all 3.0.0 beta releases and removed needs-triage label for new issues that we didn't triage yet labels Mar 19, 2025
@atul-astronomer
Copy link
Author

set() method is not implemented in task_sdk variable.py

@jason810496
Copy link
Member

jason810496 commented Mar 19, 2025

I can take on this issue and will assign it to myself.

Before I start, I just want to confirm—can I use https://github.com/apache/airflow/pull/46869/files as a reference to port the set method to Variable in TaskSDK?

cc @ashb


Update: also reference https://github.com/apache/airflow/pull/44605/files

@jason810496 jason810496 self-assigned this Mar 19, 2025
@amoghrajesh
Copy link
Contributor

@jason810496 yes you should be able to take that one as reference, specifically the Variable.get() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected_version:3.0.0beta For all 3.0.0 beta releases area:core kind:bug This is a clearly a bug priority:medium Bug that should be fixed before next release but would not block a release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants