olchas commented on a change in pull request #11061:
URL: https://github.com/apache/airflow/pull/11061#discussion_r492527472
##########
File path: airflow/models/baseoperator.py
##########
@@ -271,6 +271,9 @@ class derived from this one results in the creation of a
task object,
template_fields: Iterable[str] = ()
# Defines which files extensions to look for in the templated fields
template_ext: Iterable[str] = ()
+ # Template filed renderers indicating type of the filed for example sql,
json
Review comment:
```suggestion
# Template field renderers indicating type of the field, for example
sql, json
```
##########
File path: docs/howto/custom-operator.rst
##########
@@ -200,6 +200,35 @@ with actual value. Note that Jinja substitutes the
operator attributes and not t
In the example, the ``template_fields`` should be ``['guest_name']`` and not
``['name']``
+Additionally you may provide ``template_fields_renderers`` dictionary which
defines in what style the value
+from template field renders in Web UI. For example:
+
+.. code-block:: python
+
+ class MyRequestOperator(BaseOperator):
+ template_fields = ['request_body']
+ template_fields_renderers = {'request_body': 'json'}
+
+ @apply_defaults
+ def __init__(
+ self,
+ request_body: str,
+ **kwargs) -> None:
+ super().__init__(**kwargs)
+ self.request_body = name
Review comment:
```suggestion
self.request_body = request_body
```
##########
File path: docs/howto/custom-operator.rst
##########
@@ -200,6 +200,35 @@ with actual value. Note that Jinja substitutes the
operator attributes and not t
In the example, the ``template_fields`` should be ``['guest_name']`` and not
``['name']``
+Additionally you may provide ``template_fields_renderers`` dictionary which
defines in what style the value
+from template field renders in Web UI. For example:
+
+.. code-block:: python
+
+ class MyRequestOperator(BaseOperator):
+ template_fields = ['request_body']
+ template_fields_renderers = {'request_body': 'json'}
+
+ @apply_defaults
+ def __init__(
+ self,
+ request_body: str,
+ **kwargs) -> None:
+ super().__init__(**kwargs)
+ self.request_body = name
+
+Currently available lexers:
+
+ - bash
+ - doc
+ - json
+ - md
+ - py
+ - rst
+ - sql
+ - yaml
+
+If you will use non existing lexer the value of the template filed be rendered
as pretty printed object.
Review comment:
```suggestion
If you use a non existing lexer then the value of the template field will be
rendered as a pretty printed object.
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]