-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
[AIRFLOW-5390] Remove provide context #6074
Conversation
@@ -34,7 +34,8 @@ Passing in arguments | |||
^^^^^^^^^^^^^^^^^^^^ | |||
|
|||
Use the ``op_args`` and ``op_kwargs`` arguments to pass additional arguments | |||
to the Python callable. | |||
to the Python callable. If you use any of the :doc:`context variables <../../macros-ref>` | |||
as an argument of the provided callable, the value will be automatically injected as shown below: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All context variables can still be provided with a double-asterisk argument:
def myfunc(**context): print(context) # all variables will be provided to contextpython_operator = PythonOperator(task_id='mytask', python_callable=myfunc)
I think this part of UPDATING.md is missing in docs.
In my opinion, there is still too much documentation in the UPDATING.md file.
Maybe it's worth moving some content from updating.md file and linking to other documentation? I mentioned this file, but docstring is also useful documentation. This can discuss reserved parameter names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main goal was to simplify how it works, that you don't have to care about how this works as a user of Airflow. Besides that, I don't like the **
notation:
def myfunc(**context):
print(context['ds'])
is equivalent to:
def myfunc(ds):
print(ds)
So I don't want to point the user in the direction of using an overly verbose way of doing this. Normally in Python you should also be conscious with the kwargs stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There aren't really reserved parameter names anymore. The only clash that is possible if you do something like:
def fn(dag, ds, **context):
print(dag)
PythonOperator(
op_args=[1],
python_callable=fn
)
In this case the dag == 1
, and the ds
is just the execution date. If you would change the code to:
def fn(dag, ds, **context):
print(dag)
PythonOperator(
op_args=[1, 2],
python_callable=fn
)
Then ds
would be ds == 2
. To avoid confusion the arguments that you provide using the op_args
cannot be part of the keywords in the context. This is an edge case that will not happen in practice, and we throw an error just to keep the users their sanity.
Here I put my proposition for documentation based on note in updating.md. This is not a finished change, but I wanted to show an example. UPDATING.md
The change is backwards compatible, setting provide_context will add the provide_context variable to the kwargs (but won't do anything). PR: #5990 python.rstThe signature of the callable passed to the PythonOperator is inferred and argument values are always automatically provided. For example:
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:
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:
docstring
|
Rebased |
Looks like master is failing 😭 |
@nuclearpinguin Can you look at this? |
Add some more docs
435d8bb
to
91dc3d1
Compare
@Fokko Fixed and merged. I rebased your branch. Cross fingers. |
…provide-context-removed
Thanks @mik-laj for fixing this, appreciate it. Let's wait for Travis his verdict. |
Travis is sad 😿 Can you comfort him?
|
…provide-context-removed
Travis is sad. Can you do rebase? |
…provide-context-removed
I've rebased the branch, let's see if we can make Travis happy again. |
@Fokko static check failed |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Add some more docs. I agree with you @mik-laj that the docs where a bit minimal on the subject. WDYT?
Make sure you have checked all steps below.
Jira
Description
Tests
Commits
Documentation