FabianF92 opened a new issue #15803:
URL: https://github.com/apache/airflow/issues/15803


   
   **Apache Airflow version**: 2.0.1
   
   **Environment**: Azure App Service
   
   **What happened**:
   
   In UI, when viewing Instance Details of a task (Dag tree view -> task -> 
Instance Details) that contains special attribute `json` exception is thrown. 
This happens when the json attribute contains a dict with non-string values.
   
![image](https://user-images.githubusercontent.com/30059482/117994237-ae63ff80-b340-11eb-9449-64e4b3792abe.png)
   
   **What you expected to happen**:
   Task instance details are rendered including the special attribute json.
   
   Problem is caused by function `render(obj, lexer)` defined in `utils.py` 
(line 317, version 2.0.1):
   ```
       elif isinstance(obj, dict):
           for k, v in obj.items():
               out += Markup('<div>Dict item "{}"</div>').format(k)  # noqa
               out += Markup("<div>" + pygment_html_render(v, lexer) + "</div>")
       return out
   ```
   When value of one item is not a string but for example a dict itself, method 
`pygment_html_render(v, lexer)` can't decode data and throws error 
`AttributeError: 'dict' object has no attribute 'decode'`.
   
   **How to reproduce it**:
   Define a task with a dict as json attribute. The dict should contain at 
least one value that is another dict.
   For example, the `DatabricksSubmitRunOperator` takes `json` attribute to 
pass notebook parameters:
   ```
   json = {
             'new_cluster': {
               'spark_version': '2.1.0-db3-scala2.11',
               'num_workers': 2
             },
             'notebook_task': {
               'notebook_path': '/Users/[email protected]/PrepareData',
             },
           }
           notebook_run = DatabricksSubmitRunOperator(task_id='notebook_run', 
json=json)
   ```
   
   **Anything else we need to know**:
   
   Might be an idea to convert complete dict to json string and pass it to 
`pygments` JsonLexer instead of highlighting all items of the json.
   We wouldn't need all items displayed separately in UI as shown here:
   
![image](https://user-images.githubusercontent.com/30059482/117995232-74dfc400-b341-11eb-9750-2a26717bab78.png)
   
   
   **How often does this problem occur?**
   Every time we use json task attribute that contains non-string item values.
   
   
   


-- 
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]


Reply via email to