code generated for `date-time` fromat can not parse null response data
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
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.
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)
- Ngôn ngữ chính
- Python
- Star
- 2k
- Fork
- 293
- Merge trung bình
- 34 phút
- Pull request đã merge (30 ngày)
- 1
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openapi-generators/openapi-python-client
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
openapi-generators/openapi-python-client#1451 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
openapi-generators/openapi-python-client#1435 · 1 bình luận ·
Tất cả issue của openapi-generators/openapi-python-client
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
zostera/django-bootstrap4#894 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
use-agent-os/agent-os#3276 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·