Kafka `to_binary()` crashes on events without `datacontenttype` or with non-string attributes
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- kafka, python
調査の方向性
cloudevents/v1/kafka/conversion.py から始め、issue で言及されている新しい core Kafka binding と to_structured() を比較します。両方の再現が例外なく完了すること、datacontenttype が存在しない場合は content-type を省略すること、生成されたヘッダー内の文字列以外の拡張属性を文字列化することを確認します。
索引モデルが issue の本文から書いたものです。
説明
Description
to_binary() in cloudevents/v1/kafka/conversion.py raises on two kinds of perfectly valid CloudEvents:
1. Missing datacontenttype (optional attribute) → KeyError
headers = {}
if event["datacontenttype"]: # KeyError if unset
headers["content-type"] = event["datacontenttype"].encode("utf-8")
datacontenttype is optional, so event["datacontenttype"] raises KeyError for any event that does not set it. The sibling to_structured() in the same file already guards this with if "datacontenttype" in attrs:.
2. Non-string attribute value → AttributeError
if value is not None:
headers["ce_{0}".format(attr)] = value.encode("utf-8") # AttributeError if not str
CloudEvents extension attributes may be non-string (e.g. Integer/Boolean), so value.encode(...) raises AttributeError: 'int' object has no attribute 'encode'. The newer core Kafka binding already does str(attr_value).encode(...).
Reproduction
from cloudevents.v1.http import CloudEvent
from cloudevents.v1.kafka import to_binary
# 1) no datacontenttype -> KeyError: 'datacontenttype'
to_binary(CloudEvent({"type": "t", "source": "s"}, {"a": 1}))
# 2) non-string extension -> AttributeError: 'int' object has no attribute 'encode'
to_binary(CloudEvent({"type": "t", "source": "s",
"datacontenttype": "application/json", "ext1": 5}, {"a": 1}))
Expected behaviour
to_binary() should handle both valid events: omit the content-type header when datacontenttype is absent, and stringify non-string attribute values.
- 主要言語
- Python
- スター
- 342
- フォーク
- 65
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudevents/sdk-python のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
cloudevents/sdk-python#300 ·
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
cloudevents/sdk-python#291 · コメント 8 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 48/100
cloudevents/sdk-python#247 · コメント 2 件 ·
-
question
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
cloudevents/sdk-python#246 · コメント 5 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
cloudevents/sdk-python#213 · コメント 3 件 · リアクション 1 件 ·
cloudevents/sdk-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
OpenHands/extensions#626 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
CSCfi/sd-search-api#39 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
StevenBlack/hosts#3255 ·