YangMuye commented on a change in pull request #14024:
URL: https://github.com/apache/airflow/pull/14024#discussion_r568601212
##########
File path: airflow/www/views.py
##########
@@ -898,7 +898,7 @@ def rendered_templates(self):
content = getattr(task, template_field)
renderer = task.template_fields_renderers.get(template_field,
template_field)
if renderer in renderers:
- if isinstance(content, (dict, list)):
+ if isinstance(content, dict):
Review comment:
As a work-around, we can handle it here. But I actually believe the
logic should be handled by the renderer itself.
Just make JSON renderer the fallback renderer.
##########
File path: airflow/www/views.py
##########
@@ -898,7 +898,7 @@ def rendered_templates(self):
content = getattr(task, template_field)
renderer = task.template_fields_renderers.get(template_field,
template_field)
if renderer in renderers:
- if isinstance(content, (dict, list)):
+ if isinstance(content, dict):
Review comment:
As a work-around, we can handle it here. But I actually believe the
logic should be handled by the renderer itself.
Just make JSON renderer the fallback renderer when no renderer is specified.
##########
File path: airflow/www/views.py
##########
@@ -898,7 +898,7 @@ def rendered_templates(self):
content = getattr(task, template_field)
renderer = task.template_fields_renderers.get(template_field,
template_field)
if renderer in renderers:
- if isinstance(content, (dict, list)):
+ if isinstance(content, dict):
Review comment:
Not sure if somebody using YAML wants this feature too. I think only
some generic serialization format is capable of rendering types other than
strings.
##########
File path: airflow/www/views.py
##########
@@ -898,7 +898,7 @@ def rendered_templates(self):
content = getattr(task, template_field)
renderer = task.template_fields_renderers.get(template_field,
template_field)
if renderer in renderers:
- if isinstance(content, (dict, list)):
+ if isinstance(content, dict):
Review comment:
How about this? Actually I am even thinking whether a field accepts a
list or not is also decided by the Operator...
```diff
def get_attr_renderer():
"""Return Dictionary containing different Pygments Lexers for Rendering
& Highlighting"""
return {
- 'json': lambda x: render(x, lexers.JsonLexer),
+ 'json': lambda x: render(x if isinstance(content, (dict, list))
else json.dumps(x), lexers.JsonLexer, False),
- 'yaml': lambda x: render(x, lexers.YamlLexer),
+ 'yaml': lambda x: render(x if isinstance(content, (dict, list))
else json.dumps(x), lexers.YamlLexer, False),
}
```
##########
File path: airflow/www/views.py
##########
@@ -898,7 +898,7 @@ def rendered_templates(self):
content = getattr(task, template_field)
renderer = task.template_fields_renderers.get(template_field,
template_field)
if renderer in renderers:
- if isinstance(content, (dict, list)):
+ if isinstance(content, dict):
Review comment:
How about this? Actually I am even thinking whether a field accepts a
list or not is also decided by the Operator...
```diff
def get_attr_renderer():
"""Return Dictionary containing different Pygments Lexers for Rendering
& Highlighting"""
return {
- 'json': lambda x: render(x, lexers.JsonLexer),
+ 'json': lambda x: render(x if isinstance(content, (dict, list))
else json.dumps(x), lexers.JsonLexer, False),
- 'yaml': lambda x: render(x, lexers.YamlLexer),
+ 'yaml': lambda x: render(x if isinstance(content, (dict, list))
else json.dumps(x), lexers.YamlLexer, False),
'py': lambda x: render(get_python_source(x), lexers.PythonLexer),
}
```
python fields are already doing similar transformation.
##########
File path: airflow/www/views.py
##########
@@ -898,7 +898,7 @@ def rendered_templates(self):
content = getattr(task, template_field)
renderer = task.template_fields_renderers.get(template_field,
template_field)
if renderer in renderers:
- if isinstance(content, (dict, list)):
+ if isinstance(content, dict):
Review comment:
How about this? Actually I am even thinking whether a field accepts a
list or not is also decided by the Operator...
```diff
def get_attr_renderer():
"""Return Dictionary containing different Pygments Lexers for Rendering
& Highlighting"""
return {
- 'json': lambda x: render(x, lexers.JsonLexer),
+ 'json': lambda x: render(x if isinstance(content, (dict, list))
else json.dumps(x), lexers.JsonLexer, False),
- 'yaml': lambda x: render(x, lexers.YamlLexer),
+ 'yaml': lambda x: render(x if isinstance(content, (dict, list))
else json.dumps(x), lexers.YamlLexer, False),
'py': lambda x: render(get_python_source(x), lexers.PythonLexer),
'python_callable': lambda x: render(get_python_source(x),
lexers.PythonLexer),
}
```
python fields are already doing similar transformation.
##########
File path: airflow/www/views.py
##########
@@ -898,7 +898,7 @@ def rendered_templates(self):
content = getattr(task, template_field)
renderer = task.template_fields_renderers.get(template_field,
template_field)
if renderer in renderers:
- if isinstance(content, (dict, list)):
+ if isinstance(content, dict):
Review comment:
How about this? Actually I am even thinking whether a field accepts a
list or not is also decided by the Operator...
```diff
def get_attr_renderer():
"""Return Dictionary containing different Pygments Lexers for Rendering
& Highlighting"""
return {
- 'json': lambda x: render(x, lexers.JsonLexer),
+ 'json': lambda x: render(x if isinstance(content, (dict, list))
else json.dumps(x), lexers.JsonLexer),
- 'yaml': lambda x: render(x, lexers.YamlLexer),
+ 'yaml': lambda x: render(x if isinstance(content, (dict, list))
else json.dumps(x), lexers.YamlLexer),
'py': lambda x: render(get_python_source(x), lexers.PythonLexer),
'python_callable': lambda x: render(get_python_source(x),
lexers.PythonLexer),
}
```
python fields are already doing similar transformation.
----------------------------------------------------------------
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]