openapi-generators / openapi-generators/openapi-python-client
code generated for `date-time` fromat can not parse null response data
未关闭
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 2k
- 派生
- 293
- 平均合并
- 34 分钟
- 30 天内合并 PR
- 1
描述
Describe the bug
code generated for date-time fromat in models file like this for now:
_update_time = d.pop("updateTime", UNSET)
update_time: Union[Unset, datetime.datetime]
if isinstance(_update_time, Unset):
update_time = UNSET
else:
update_time = isoparse(_update_time)
if response data of updateTime field is null, the _update_time variable will be set to None, so isoparse function will rasie TypeError except.
self = <dateutil.parser.isoparser.isoparser object at 0x7f94bf7ae950>, dt_str = None
def _parse_isodate_common(self, dt_str):
> len_str = len(dt_str)
E TypeError: object of type 'NoneType' has no len()
../../../../.local/lib/python3.10/site-packages/dateutil/parser/isoparser.py:213: TypeError
OpenAPI Spec File
{
"updateTime": {
"type": "string",
"description": "updateTime",
"format": "date-time"
}
}
Desktop (please complete the following information):
- OS: windows wsl ubuntu 22.0
- Python Version: 3.10.0
- openapi-python-client version 0.17.2
Additional context
my suggestion is, adding branch check value is None before call isoparse function, generate code like this:
_update_time = d.pop("updateTime", UNSET)
update_time: Union[Unset, datetime.datetime]
if isinstance(_update_time, Unset):
update_time = UNSET
elif _update_time is None:
update_time = None
else:
update_time = isoparse(_update_time)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先定位为具有 date-time 格式的 OpenAPI 字段生成模型反序列化的生成器逻辑,然后使用提供的 nullable updateTime schema 和响应数据重现该问题。为 null date-time 值添加回归测试,并验证生成的客户端能够接受该响应而不会引发 TypeError。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100