You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "potiuk (via GitHub)" <gi...@apache.org> on 2023/08/16 12:32:32 UTC

[GitHub] [airflow] potiuk commented on a diff in pull request #33430: Allow context key args to not provide a default

potiuk commented on code in PR #33430:
URL: https://github.com/apache/airflow/pull/33430#discussion_r1295823498


##########
docs/apache-airflow/tutorial/taskflow.rst:
##########
@@ -578,23 +578,31 @@ task to copy the same file to a date-partitioned storage location in S3 for long
 Accessing context variables in decorated tasks
 ----------------------------------------------
 
-When running your callable, Airflow will pass a set of keyword arguments that can be used in your
-function. This set of kwargs correspond exactly to what you can use in your Jinja templates.
-For this to work, you need to define ``**kwargs`` in your function header, or you can add directly the
-keyword arguments you would like to get - for example with the below code your callable will get
-the values of ``ti`` and ``next_ds`` context variables. Note that when explicit keyword arguments are used,
-they must be made optional in the function header to avoid ``TypeError`` exceptions during DAG parsing as
-these values are not available until task execution.
+When running your callable, Airflow will pass a set of keyword arguments that
+can be used in your function. This set of kwargs correspond exactly to what you
+can use in your Jinja templates. For this to work, you can add context keys you
+would like to receive in the function as keyword arguments.
 
-With explicit arguments:
+For example, the callable in the code block below will get values of the ``ti``
+and ``next_ds`` context variables:
 
 .. code-block:: python
 
    @task
-   def my_python_callable(ti=None, next_ds=None):
+   def my_python_callable(*, ti, next_ds):
        pass
 
-With kwargs:
+..
+
+You can also choose to receive the entire context with ``**kwargs``. Note that
+this is can incur a slight performance penalties since Airflow will need to

Review Comment:
   ```suggestion
   this can incur a slight performance penalty since Airflow will need to
   ```



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org