code generated for `date-time` fromat can not parse null response data
還沒有人認領這個 Issue。
評估
研究方向
先定位為具有 date-time 格式的 OpenAPI 欄位產生模型反序列化的產生器邏輯,然後使用提供的 nullable updateTime schema 和回應資料重現該問題。為 null date-time 值加入回歸測試,並驗證產生的用戶端能夠接受該回應而不會引發 TypeError。
由索引模型根據 Issue 內容生成。
描述
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)
- 主要語言
- Python
- 星號
- 2k
- 分支
- 293
- 平均合併
- 34 分鐘
- 30 天內合併 PR
- 1
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
openapi-generators/openapi-python-client 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
-
難度 2/5 1-3 小時 新手友好度 65/100
-
難度 3/5 1-2 天 新手友好度 72/100
openapi-generators/openapi-python-client#1451 · 1 則留言 ·
-
難度 3/5 1-2 天 新手友好度 52/100
-
難度 3/5 1-2 天 新手友好度 64/100
openapi-generators/openapi-python-client#1435 · 1 則留言 ·
查看 openapi-generators/openapi-python-client 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 90/100
-
bug
難度 2/5 1-3 小時 新手友好度 86/100
zostera/django-bootstrap4#894 ·
-
難度 2/5 1-3 小時 新手友好度 78/100
use-agent-os/agent-os#3276 ·
-
難度 2/5 1-3 小時 新手友好度 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
難度 2/5 1-3 小時 新手友好度 88/100
NousResearch/hermes-agent#117848 ·