cloudevents.http.from_http binary incorrect error messages
まだ誰も着手していません。
評価
調査の方向性
cloudevents/http/http_methods.py から始め、cloudevents/http/event_type.py、cloudevents/sdk/converters/binary.py、cloudevents/sdk/converters/util.py を通るバイナリ解析の経路を追跡します。issue に示されているフィールド欠落のケースを再現し、ce-id、ce-source、または ce-type が欠落している場合に、specversion ではなく対応する欠落フィールドが報告されることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Expected Behavior
When using cloudevents.http.from_http(headers, body), an event that is missing any of the required fields should result in a cloud_exceptions.MissingRequiredFields exception with a message that indicates which field is missing.
Actual Behavior
When given a Binary Cloud Event that is missing a required field ce-id, ce-source, or ce-type, it will return a MissingRequiredFields error with the incorrect error message Failed to find specversion in HTTP request.
Steps to Reproduce the Problem
from cloudevents.http import from_http
from cloudevents.exceptions import MissingRequiredFields
# Correctly does not result in an error if all required fields are present
def test_from_http():
event = from_http({"ce-specversion": "1.0", "ce-id":"123", "ce-type": "test-type", "ce-source": "test-source"}, "{}")
assert event["id"] == "123"
# Returns an incorrect error message
def test_from_http_missing_id_binary():
try:
event = from_http({"ce-specversion": "1.0", "ce-type": "test-type", "ce-source": "test-source"}, "{}")
assert 1 == 2
except MissingRequiredFields as e:
assert "Failed to find specversion in HTTP request" == str(e)
# Returns the appropriate message
def test_from_http_missing_id_structured():
try:
event = from_http({}, "{\"specversion\": \"1.0\", \"type\": \"test-type\", \"source\": \"test-source\"}")
assert 1 == 2
except MissingRequiredFields as e:
assert "Missing required attributes: {'id'}" == str(e)
The code flow is as follows:
- it checks
is_binary(headers)https://github.com/cloudevents/sdk-python/blob/b83bfc58eb851f9b91a96f4665754d9bb82cd74e/cloudevents/http/http_methods.py#L46 - It calls
binary_parser.can_readhttps://github.com/cloudevents/sdk-python/blob/b83bfc58eb851f9b91a96f4665754d9bb82cd74e/cloudevents/http/event_type.py#L6-L16 - it calls
has_binary_headershttps://github.com/cloudevents/sdk-python/blob/b83bfc58eb851f9b91a96f4665754d9bb82cd74e/cloudevents/sdk/converters/binary.py#L29-L35 has_binary_headerschecks for the presence of all required fields, which in this test case is false because it is missingce-idhttps://github.com/cloudevents/sdk-python/blob/b83bfc58eb851f9b91a96f4665754d9bb82cd74e/cloudevents/sdk/converters/util.py#L4-L10- it then falls through and tries to get the specversion here https://github.com/cloudevents/sdk-python/blob/b83bfc58eb851f9b91a96f4665754d9bb82cd74e/cloudevents/http/http_methods.py#L57
- specversion is never set and the error gets thrown here https://github.com/cloudevents/sdk-python/blob/b83bfc58eb851f9b91a96f4665754d9bb82cd74e/cloudevents/http/http_methods.py#L64-L67
I think that the solution might be as simple as changing all of the ands to ors in the has_binary_headers method in step 4.
Specifications
- Platform: Mac OS
- Python Version: 3.9.4
- 主要言語
- Python
- スター
- 342
- フォーク
- 65
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudevents/sdk-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudevents/sdk-python#304 ·
-
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 件 ·
cloudevents/sdk-python の issue をすべて見る
似ている issue
-
agent-ready documentation needs-triage
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" オープン
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
instance instance add
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
searxng/searx-instances#939 · コメント 1 件 ·
-
area-deployment area-integrations triage:bot-seen
難易度 2/5 半日 初心者へのやさしさ 86/100