hussein-awala opened a new issue, #40773: URL: https://github.com/apache/airflow/issues/40773
### Apache Airflow version 2.9.2 ### If "Other Airflow 2 version" selected, which one? _No response_ ### What happened? Created from https://stackoverflow.com/questions/78738738/airflow-xcom-pull-from-a-custompriorityweightplugin I want to prioritize a run_test_task in DAG B depending on an xcom value from a task get_username in DAG A. DAG B is triggered by a TriggerDagRunOperator trigger_task in DAG A. The idea is to use [Custom Weight Rule](https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/priority-weight.html#custom-weight-rule) that is based on a built-in _DownstreamPriorityWeightStrategy class. Here is my simplified plugin code: class CustomPriorityStrategy(_DownstreamPriorityWeightStrategy): ```python @provide_session def get_weight(self, ti: TaskInstance, session: Session) -> int: weight = super().get_weight(ti) username = ti.xcom_pull(task_ids='get_username', session=session) if username == "john": weight += 1000 return weight ``` Here is the usage: ```python run_test_task = RunTestOperator( ... weight_rule="custom_priority_weight_strategy.CustomPriorityStrategy", ... ``` The trigger_task fails with ``` Traceback (most recent call last): File "/home/airflow/.local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3901, in _bulk_save_mappings persistence._bulk_insert( File "/home/airflow/.local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 74, in _bulk_insert connection = session_transaction.connection(base_mapper) File "/home/airflow/.local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 627, in connection self._assert_active() File "/home/airflow/.local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 620, in _assert_active raise sa_exc.ResourceClosedError(closed_msg) sqlalchemy.exc.ResourceClosedError: This transaction is closed ``` ### What you think should happen instead? _No response_ ### How to reproduce ```python @provide_session def get_weight(self, ti: TaskInstance, session: Session) -> int: weight = super().get_weight(ti) username = ti.xcom_pull(task_ids='get_username', session=session) if username == "john": weight += 1000 return weight ``` ### Operating System linux ### Versions of Apache Airflow Providers _No response_ ### Deployment Official Apache Airflow Helm Chart ### Deployment details _No response_ ### Anything else? _No response_ ### Are you willing to submit PR? - [X] 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]
