potiuk commented on a change in pull request #18868:
URL: https://github.com/apache/airflow/pull/18868#discussion_r726099850
##########
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:
OK. Just checked.This is the root of the problem then. When
`provide_context` was removed from PythonOpertor, the documentation about
passing context variables was removed as well because it was part of the
`provide_context` docstring. Now anyone new coming here has no idea that
context variables are passed - and it's not mentioned either in PythonOperator
nor in @task decorator.
I will add the right description to both.
--
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]