Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rihkddd opened this issue Mar 12, 2024 · 0 comments
Open

Comments

@rihkddd
Copy link

rihkddd commented Mar 12, 2024

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant