openapi-generators / openapi-generators/openapi-python-client

code generated for `date-time` fromat can not parse null response data

未關閉
#997 2 則留言 4 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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)

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先定位為具有 date-time 格式的 OpenAPI 欄位產生模型反序列化的產生器邏輯,然後使用提供的 nullable updateTime schema 和回應資料重現該問題。為 null date-time 值加入回歸測試,並驗證產生的用戶端能夠接受該回應而不會引發 TypeError。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
api
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。