potiuk commented on a change in pull request #18868:
URL: https://github.com/apache/airflow/pull/18868#discussion_r726089376
##########
File path: docs/apache-airflow/tutorial_taskflow_api.rst
##########
@@ -286,6 +286,26 @@ In the above code block, a
:class:`~airflow.providers.http.operators.http.Simple
was captured via :doc:`XCOMs </concepts/xcoms>`. This XCOM result, which is
the task output, was then passed
to a TaskFlow decorated task which parses the response as JSON - and the rest
continues as expected.
+Accessing context from decorated tasks
+--------------------------------------
+
+While the TaskFlow API transparently handles most of the Airflow boilerplate
(such as passing inputs/outputs
+between tasks), sometimes you might want to access the operator context
directly. You can do it via
+``get_current_context`` method of the Python operator.
+
+.. code-block:: python
+
+ from airflow.operators.python import task, get_current_context
+
+
+ @task
+ def my_task():
+ context = get_current_context()
+ ti = context["ti"]
Review comment:
Out of couriosity @ashb - can we pass any context variables this way ?
I am happy to update this chapter and explicitly state this because I
believe it Is not mentioned in any of taskflow-API documentation or the
tutorial (unless I am mistaken and missed it :) )
I could not find it mentioned anywhere in the documentation (and it's far
from obvious - i.e. I was not aware of that and I looked through documentation
of TaskFlow API several times recently and answered several people to use
`get_current_context()` because I was not aware of that. So I would love to
know how it works.
--
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]