BasPH commented on a change in pull request #5990: [AIRFLOW-5390] Remove 
provide context

 File path:
 @@ -37,9 +37,15 @@ assists users migrating to a new version.
 - [Airflow](#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:
   def myfunc(execution_date):
   python_operator = PythonOperator(task_id='mytask', python_callable=myfunc, 
   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:
   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:
   def myfunc(dag):
       # raises a ValueError because "dag" is a reserved name
       # valid signature example: myfunc(mydag)
   python_operator = PythonOperator(
   The change is backwards compatible, setting `provide_context` will add the 
`provide_context` variable to the kwargs (but won't do anything).

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:

With regards,
Apache Git Services

Reply via email to