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

Change set_current_context location #39637

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

romsharon98
Copy link
Collaborator

@romsharon98 romsharon98 commented May 15, 2024

closes: #24483

checked this changed works by this dag:

from airflow.operators.python import get_current_context, PythonOperator


def some_function_in_your_library():
    return 'rom'

def some_function_in_your_library2(name):
    print(name)


def config(task_id):
    context = get_current_context()
    _result = context['ti'].xcom_pull(task_ids=task_id)
    return _result

user_defined_macros = {"config": config}

from airflow.models.dag import DAG

with DAG(dag_id='my_dag', user_defined_macros=user_defined_macros) as dag:
    task1 = PythonOperator(python_callable=some_function_in_your_library, task_id='my_task')
    task2 = PythonOperator(python_callable=some_function_in_your_library2, task_id='my_task2', op_kwargs={"name": "{{config('my_task')}}"})
    task1 >> task2

task2 print rom

cc: @vanchaxy


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@romsharon98 romsharon98 force-pushed the feature/move-context-manager-location branch from a091072 to 182979b Compare May 15, 2024 12:09
@eladkal eladkal added this to the Airflow 2.9.2 milestone May 15, 2024
Copy link
Contributor

@josh-fell josh-fell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes looks OK to me, but FWIW I did test the example in the PR description on 2.9.0 and it works out of the box without this change. Maybe there is another example (or even a test case) that shows the value of this update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow context usage in user_defined_macros
3 participants