Skip to content

Direct database access via the ORM is not allowed in Airflow 3.0, when trying to clean XCom inside a DAG #50944

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

Closed
1 of 2 tasks
gvazharov opened this issue May 22, 2025 · 4 comments
Labels
area:core kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet

Comments

@gvazharov
Copy link

gvazharov commented May 22, 2025

Apache Airflow version

3.0.1

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

No response

What happened?

Hi,

normally I am cleaning up at the end of each DAG execution the DAG XCom's. I have now upgraded to the newest Airflow 3.0.1 version and found that this is not any more possible because of the following restriction: Direct database access via the ORM is not allowed in Airflow 3.0

Normally I was using the following code to clean up the XCom's:

from airflow.utils.db import provide_session
from airflow.models import XCom

@provide_session
def cleanup_xcom(session=None):
    logging.info('Cleaning XCom')
    session.query(XCom).filter(XCom.dag_id == "airflow_activity_context_migrator").delete()
    logging.info('XCom clean successful!')

Now I have tried also this one, which is based on the official XCom Documentation :

from airflow.models.xcom import XComModel

def cleanup_xcom():
    logging.info('Cleaning XCom')
    XComModel.clear(dag_id='airflow_test')
    logging.info('XCom clean successful!')

Still getting the same error and my DAG fails.

I am quite sure that, my first approach was not the best one, because I was querying and deleting elements directly, which I though is the problem. When I tested with the XComModel.clear() function and still getting the same error, I expected it to work, because it is a predefined function and the user passes only the required arguments, which is not so harmful.

What you think should happen instead?

I think there should be definitely a way, how the people can delete their XCom's inside a DAG and the XComModel.clear() function should have probably an exclusion for this new restriction, which forbites the direct db access via ORM.

How to reproduce

Just execute the following in any DAG:

from airflow.models.xcom import XComModel

def cleanup_xcom():
    logging.info('Cleaning XCom')
    XComModel.clear(dag_id='airflow_test')
    logging.info('XCom clean successful!')

Operating System

Red Hat Enterprise Linux 8.10 (Ootpa)

Versions of Apache Airflow Providers

No response

Deployment

Other Docker-based deployment

Deployment details

I am running Airflow 3.0.1 with KubernetesExecutor on Openshift

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@gvazharov gvazharov added kind:bug This is a clearly a bug area:core needs-triage label for new issues that we didn't triage yet labels May 22, 2025
@vatsrahul1001
Copy link
Contributor

Access to database is not allowed in Airflow 3.0 due to security concerns i.e you cannot access metadatabase from worker anymore. This is not a bug but a feature of Airflow 3.0

@potiuk
Copy link
Member

potiuk commented May 22, 2025

Access to database is not allowed in Airflow 3.0 due to security concerns i.e you cannot access metadatabase from worker anymore. This is not a bug but a feature of Airflow 3.0

BTW. You should be able to use it with REST API I think.

@gvazharov
Copy link
Author

Thanks for you answer. Can you tell me how are the Airflow users, supposed to clean their XCom's, which are integral part of the whole process chain, or this will be not any more possible inside a DAG.

Thanks

@potiuk
Copy link
Member

potiuk commented May 22, 2025

Thanks for you answer. Can you tell me how are the Airflow users, supposed to clean their XCom's, which are integral part of the whole process chain, or this will be not any more possible inside a DAG.

Just to repeat: BTW. You should be able to use it with REST API I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:core kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet
Projects
None yet
Development

No branches or pull requests

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy