`JSONFormat` shouldn't depend on Content-Type to avoid generating invalid JSON
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Bắt đầu tại src/cloudevents/core/formats/json.py ở dòng được tham chiếu và kiểm tra cách JSONFormatter xử lý data và Content-Type. Xác minh rằng dữ liệu dạng dictionary tạo ra JSON hợp lệ ngay cả với application/octet-stream, rồi chạy các bài kiểm thử formatter liên quan hoặc bổ sung coverage cho trường hợp này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi,
i just upgraded my service to v2.
The problem:
- the service which produces the cloudevents is maintained by another team, i.e. not in my control
- they send the events with Content-Type
application/octet-stream - therefore, in my tests i also emulate sending the events with that Content-Type:
event = CloudEvent(
attributes={..., "datacontenttype": "application/octet-stream"},
data=payload, # <- this is a dictionary
)
message = tobinary_event(event)
client.post("/trigger", content=message.body, headers=message.headers)
now my tests started to send invalid json data (using single quotes instead of double quotes). The reason is this line. E.g. it converts {"asdf": True} to b"{'asdf', True}".
i initially didn't realise this comes from my test case and assumed the SDK generates the invalid data. It took me a while to figure out that only my test setup is wrong.
Proposed solution:
I think str(data).encode("utf-8") is a bad default. Instead, the JSONFormatter should always try to return dumps(data, cls=_JSONEncoderWithDatetime).encode("utf-8"), regardless of the content type. it's the JSONFormatter, so when i pass in a dictionary, i expect it to generate valid json. If it can't, then it's fine to fail with a json.JSONDecodeError or the like. Imo, failing is better than silently generating invalid request data.
Wdyt?
- Ngôn ngữ chính
- Python
- Star
- 342
- Fork
- 65
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
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 cloudevents/sdk-python
-
Kafka `to_binary()` crashes on events without `datacontenttype` or with non-string attributes Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cloudevents/sdk-python#304 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
cloudevents/sdk-python#300 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 48/100
cloudevents/sdk-python#247 · 2 bình luận ·
-
question
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
cloudevents/sdk-python#246 · 5 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
cloudevents/sdk-python#213 · 3 bình luận · 1 reaction ·
Tất cả issue của cloudevents/sdk-python
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
use-agent-os/agent-os#3314 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
BasedHardware/omi#15662 · 1 bình luận ·
-
documentation help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
AiursoftWeb/AnduinOS-2#19 ·