BasPH commented on a change in pull request #5990: [AIRFLOW-5390] Remove provide context URL: https://github.com/apache/airflow/pull/5990#discussion_r322674559
########## File path: UPDATING.md ########## @@ -37,9 +37,15 @@ assists users migrating to a new version. - [Airflow 1.7.1.2](#airflow-1712) <!-- END doctoc generated TOC please keep comment here to allow auto update --> + ## Airflow Master +### Remove provide_context + +Instead of settings `provide_context` we're automagically inferring the signature of the callable that is being passed to the PythonOperator. The only behavioural change in is that using a key that is already in the context in the function, such as `dag` or `ds` is not allowed anymore and will thrown an exception. If the `provide_context` is still explicitly passed to the function, it will just end up in the `kwargs`, which can cause no harm. Review comment: @Fokko since this is a user-facing change, I suggest a bit more explanation (I couldn't nest triple backticks in GitHub so couldn't make a suggestion): ---------------------- `provide_context` argument on the PythonOperator was removed. The signature of the callable passed to the PythonOperator is now inferred and argument values are always automatically provided. There is no need to explicitly provide or not provide the context anymore. For example: ```python def myfunc(execution_date): print(execution_date) python_operator = PythonOperator(task_id='mytask', python_callable=myfunc, dag=dag) ``` Notice you don't have to set `provide_context=True`, variables from the task context are now automatically detected and provided. All context variables can still be provided with a double-asterisk argument: ```python def myfunc(**context): print(context) # all variables will be provided to context python_operator = PythonOperator(task_id='mytask', python_callable=myfunc) ``` The task context variable names are reserved names in the callable function, hence a clash with `op_args` and `op_kwargs` results in an exception: ```python def myfunc(dag): # raises a ValueError because "dag" is a reserved name # valid signature example: myfunc(mydag) python_operator = PythonOperator( task_id='mytask', op_args=[1], python_callable=myfunc, ) ``` The change is backwards compatible, setting `provide_context` will add the `provide_context` variable to the kwargs (but won't do anything). PR: https://github.com/apache/airflow/pull/5990 ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services