uranusjr commented on code in PR #35017: URL: https://github.com/apache/airflow/pull/35017#discussion_r1396735049
########## docs/apache-airflow/core-concepts/operators.rst: ########## @@ -158,37 +158,50 @@ See the `Jinja documentation <https://jinja.palletsprojects.com/en/2.11.x/api/#j Some operators will also consider strings ending in specific suffixes (defined in ``template_ext``) to be references to files when rendering fields. This can be useful for loading scripts or queries directly from files rather than including them into DAG code. -For example, consider a BashOperator which runs a multi-line bash script, this will load the file at ``script.sh`` and use its contents as the value for ``bash_callable``: +For example, consider a BashOperator which runs a multi-line bash script, this will load the file at ``script.sh`` and use its contents as the value for ``bash_command``: .. code-block:: python run_script = BashOperator( task_id="run_script", - bash_callable="script.sh", + bash_command="script.sh", ) By default, paths provided in this way should be provided relative to the DAG's folder (as this is the default Jinja template search path), but additional paths can be added by setting the ``template_searchpath`` arg on the DAG. -In some cases you may want to disable template rendering on specific fields or prevent airflow from trying to read template files for a given suffix. Consider the following task: +In some cases, you may want to exclude a string from templating and use it directly. Consider the following task: .. code-block:: python print_script = BashOperator( task_id="print_script", - bash_callable="cat script.sh", + bash_command="cat script.sh", ) +This will fail with ``TemplateNotFound: cat script.sh``, but we can prevent airflow from treating this value as a reference to a file by wrapping it in :func:`~airflow.util.template.literal`. Review Comment: ```suggestion This will fail with ``TemplateNotFound: cat script.sh`` since Airflow would treat the string as a path to a file, not a command. We can prevent airflow from treating this value as a reference to a file by wrapping it in :func:`~airflow.util.template.literal`. ``` ########## docs/apache-airflow/core-concepts/operators.rst: ########## @@ -158,37 +158,50 @@ See the `Jinja documentation <https://jinja.palletsprojects.com/en/2.11.x/api/#j Some operators will also consider strings ending in specific suffixes (defined in ``template_ext``) to be references to files when rendering fields. This can be useful for loading scripts or queries directly from files rather than including them into DAG code. -For example, consider a BashOperator which runs a multi-line bash script, this will load the file at ``script.sh`` and use its contents as the value for ``bash_callable``: +For example, consider a BashOperator which runs a multi-line bash script, this will load the file at ``script.sh`` and use its contents as the value for ``bash_command``: .. code-block:: python run_script = BashOperator( task_id="run_script", - bash_callable="script.sh", + bash_command="script.sh", ) By default, paths provided in this way should be provided relative to the DAG's folder (as this is the default Jinja template search path), but additional paths can be added by setting the ``template_searchpath`` arg on the DAG. -In some cases you may want to disable template rendering on specific fields or prevent airflow from trying to read template files for a given suffix. Consider the following task: +In some cases, you may want to exclude a string from templating and use it directly. Consider the following task: .. code-block:: python print_script = BashOperator( task_id="print_script", - bash_callable="cat script.sh", + bash_command="cat script.sh", ) +This will fail with ``TemplateNotFound: cat script.sh``, but we can prevent airflow from treating this value as a reference to a file by wrapping it in :func:`~airflow.util.template.literal`. +This approach disables the rendering of both macros and files and can be applied to selected nested fields while retaining the default templating rules for the remainder of the content. -This will fail with ``TemplateNotFound: cat script.sh``, but we can prevent airflow from treating this value as a reference to a file by overriding ``template_ext``: +.. code-block:: python + Review Comment: ```suggestion from airflow.utils.template import literal ``` -- 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]
