aws / aws/aws-step-functions-data-science-sdk-python

Execution list_events html output fails with boolean properties for inputDetails.

未关闭
#93 4 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug
主要语言
Python
星标
299
派生
84
PR 合并指标
30 天内没有已合并 PR

描述

When an event includes boolean properties the `execution.list_events(html=True)` method fails with error:

```
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
----> 1 execution.list_events(html=True) # Bug

~/anaconda3/envs/python3/lib/python3.6/site-packages/stepfunctions/workflow/stepfunctions.py in list_events(self, max_items, reverse_order, html)
487
488 if html:
--> 489 return HTML(events_list.to_html())
490 else:
491 return events_list

~/anaconda3/envs/python3/lib/python3.6/site-packages/stepfunctions/workflow/stepfunctions.py in to_html(self)
45
46 def to_html(self):
---> 47 return EventsTableWidget(self).show()
48
49

~/anaconda3/envs/python3/lib/python3.6/site-packages/stepfunctions/workflow/widgets/events_table.py in __init__(self, events)
141 timestamp=format_time(event.get("timestamp")),
142 event_detail=self._format_event_detail(event)
--> 143 ) for event in events]
144
145 self.template = Template(TABLE_TEMPLATE.format(table_rows='\n'.join(table_rows)))

~/anaconda3/envs/python3/lib/python3.6/site-packages/stepfunctions/workflow/widgets/events_table.py in (.0)
141 timestamp=format_time(event.get("timestamp")),
142 event_detail=self._format_event_detail(event)
--> 143 ) for event in events]
144
145 self.template = Template(TABLE_TEMPLATE.format(table_rows='\n'.join(table_rows)))

~/anaconda3/envs/python3/lib/python3.6/site-packages/stepfunctions/workflow/widgets/events_table.py in _format_event_detail(self, event)
307 def _format_event_detail(self, event):
308 event_details = self._get_step_detail(event)
--> 309 self._unpack_to_proper_dict(event_details)
310 return json.dumps(event_details, indent=4)
311

~/anaconda3/envs/python3/lib/python3.6/site-packages/stepfunctions/workflow/widgets/events_table.py in _unpack_to_proper_dict(self, dictionary)
313 for k, v in dictionary.items():
314 if isinstance(v, dict):
--> 315 self._unpack_to_proper_dict(v)
316 else:
317 dictionary[k] = self._load_json(v)

~/anaconda3/envs/python3/lib/python3.6/site-packages/stepfunctions/workflow/widgets/events_table.py in _unpack_to_proper_dict(self, dictionary)
315 self._unpack_to_proper_dict(v)
316 else:
--> 317 dictionary[k] = self._load_json(v)
318
319 def _load_json(self, value):

~/anaconda3/envs/python3/lib/python3.6/site-packages/stepfunctions/workflow/widgets/events_table.py in _load_json(self, value)
319 def _load_json(self, value):
320 try:
--> 321 return json.loads(value)
322 except ValueError as e:
323 return value

~/anaconda3/envs/python3/lib/python3.6/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 if not isinstance(s, (bytes, bytearray)):
347 raise TypeError('the JSON object must be str, bytes or bytearray, '
--> 348 'not {!r}'.format(s.__class__.__name__))
349 s = s.decode(detect_encoding(s), 'surrogatepass')
350

TypeError: the JSON object must be str, bytes or bytearray, not 'bool'
```

This is due to the `{'truncated': False}` value in the following event:

```
{'timestamp': datetime.datetime(2020, 10, 6, 2, 41, 57, 614000, tzinfo=tzlocal()),
'type': 'ExecutionStarted',
'id': 1,
'previousEventId': 0,
'executionStartedEventDetails': {'input': '{\n "ExperimentName": "mlops-nyctaxi",\n "TrialName": "mlops-nyctaxi-7f99979c077d11ebbed6ad48a7dcc771",\n "GitBranch": "master",\n "GitCommitHash": "xxx",\n "DataVersionId": "yyy",\n "BaselineJobName": "mlops-nyctaxi-7f99979c077d11ebbed6ad48a7dcc771",\n "BaselineOutputUri": "s3://sagemaker-us-east-1-691313291965/nyctaxi/monitoring/baseline/mlops-nyctaxi-pbl-7f99979c077d11ebbed6ad48a7dcc771",\n "TrainingJobName": "mlops-nyctaxi-7f99979c077d11ebbed6ad48a7dcc771"\n}',
'inputDetails': {'truncated': False},
'roleArn': 'arn:aws:iam::691313291965:role/mlops-nyctaxi-sfn-execution-role'}}
```

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 stepfunctions/workflow/widgets/events_table.py 开始,重点查看 _unpack_to_proper_dict 和 _load_json,然后使用 inputDetails 包含 truncated: False 的事件,通过 execution.list_events(html=True) 重现该故障。完成标准是 HTML 事件输出在没有 TypeError 的情况下完成渲染,同时保留布尔属性。

由索引模型根据 Issue 内容生成。

评估

技术栈
aws, python
领域
backend
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。