Skip to content

List and Dict template fields are rendered as JSON. #13988

Description

@YangMuye

Apache Airflow version: 2.0.0

Kubernetes version (if you are using kubernetes) (use kubectl version): n/a

Environment: Linux

  • Cloud provider or hardware configuration: amd64
  • OS (e.g. from /etc/os-release): Centos 7
  • Kernel (e.g. uname -a):
  • Install tools: pip
  • Others:

What happened:

The field sql is rendered as a serialized json ["select 1 from dual", "select 2 from dual"] instead of a list of syntax-highlighted SQL statements.

image

What you expected to happen:

lists and dicts should be rendered as lists and dicts rather than serialized json unless the template_field_renderer is json

image

How to reproduce it:

from airflow import DAG
from airflow.providers.oracle.operators.oracle import OracleOperator

with DAG("demo", default_args={owner='airflow'}, start_date= pendulum.yesterday(), schedule_interval='@daily',) as dag:
    OracleOperator(task_id='single', sql='select 1 from dual')
    OracleOperator(task_id='list', sql=['select 1 from dual', 'select 2 from dual'])

Anything else we need to know:

Introduced by #11061, .

A quick and dirty work-around:

Edit file airflow/www/views.py

            if renderer in renderers:
-                if isinstance(content, (dict, list)):
+               if isinstance(content, (dict, list)) and renderer is renderers['json']:
                    content = json.dumps(content, sort_keys=True, indent=4)
                html_dict[template_field] = renderers[renderer](content)

Metadata

Metadata

Assignees

Labels

area:UIRelated to UI/UX. For Frontend Developers.kind:bugThis is a clearly a bugpriority:lowBug with a simple workaround that would not block a release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions