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

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

Đang mở
#997 2 bình luận 4 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
2k
Fork
293
Merge trung bình
34 phút
Pull request đã merge (30 ngày)
1

Mô tả

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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách xác định logic của generator tạo ra quá trình deserialize model cho các trường OpenAPI có định dạng date-time, sau đó tái hiện vấn đề bằng schema nullable updateTime và dữ liệu response được cung cấp. Thêm một regression test cho các giá trị date-time null và xác minh rằng các client được tạo chấp nhận response mà không phát sinh TypeError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.