question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

List and Dict template fields are rendered as JSON.

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
anushkrishnavcommented, Feb 1, 2021

Awesome thanks !! @mik-laj

0reactions
turbaszekcommented, Feb 2, 2021

The breaking to individual item was the original behavior before #11061 ? I don’t remember this

I don’t remember it too, but it may have been only issue of sql.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get list of fields from list of objects (dict) imported from json
I am developing a tool for generating docx reports from a database and a template file. The first part of the tool is...
Read more >
Parse JSON to fill in elm-UI Template - Learn - Elm Discourse
Hi. I have a bunch of preexisting JSON files. This JSON contains business information that I need to render. For starters I'd like...
Read more >
Dictionary attributes - Product Documentation | ServiceNow
Name Value Target Element allow_null true/false field_name field allow_public true/false table_name field allow_references true/false field_name field
Read more >
Working With JSON Data in Python - GeeksforGeeks
Python supports JSON through a built-in package called JSON. ... to load from a string, otherwise, the root object is in a list...
Read more >
Request and response objects - Django documentation
A dictionary-like object containing all given HTTP POST parameters, ... For use in, for example, Django templates, headers can also be looked up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found