You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
fromcloudevents.httpimportfrom_httpfromcloudevents.exceptionsimportMissingRequiredFields# Correctly does not result in an error if all required fields are presentdeftest_from_http():
event=from_http({"ce-specversion": "1.0", "ce-id":"123", "ce-type": "test-type", "ce-source": "test-source"}, "{}")
assertevent["id"] =="123"# Returns an incorrect error messagedeftest_from_http_missing_id_binary():
try:
event=from_http({"ce-specversion": "1.0", "ce-type": "test-type", "ce-source": "test-source"}, "{}")
assert1==2exceptMissingRequiredFieldsase:
assert"Failed to find specversion in HTTP request"==str(e)
# Returns the appropriate messagedeftest_from_http_missing_id_structured():
try:
event=from_http({}, "{\"specversion\": \"1.0\", \"type\": \"test-type\", \"source\": \"test-source\"}")
assert1==2exceptMissingRequiredFieldsase:
assert"Missing required attributes: {'id'}"==str(e)
I would also like to see this fixed. It would greatly improve the user experience. What I would also consider doing in this step is adding an attribute to the MissingRequiredFields exception that specifies which fields are actually missing. This would make it easier to handle the exception by another application.
We are seeing this issue, and debugging was a headache because of it. It looks like the PR went stale with no outcome from a WG meeting -- is this true?
Expected Behavior
When using
cloudevents.http.from_http(headers, body)
, an event that is missing any of the required fields should result in acloud_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
, orce-type
, it will return aMissingRequiredFields
error with the incorrect error messageFailed to find specversion in HTTP request
.Steps to Reproduce the Problem
The code flow is as follows:
is_binary(headers)
sdk-python/cloudevents/http/http_methods.py
Line 46 in b83bfc5
binary_parser.can_read
sdk-python/cloudevents/http/event_type.py
Lines 6 to 16 in b83bfc5
has_binary_headers
sdk-python/cloudevents/sdk/converters/binary.py
Lines 29 to 35 in b83bfc5
has_binary_headers
checks for the presence of all required fields, which in this test case is false because it is missingce-id
sdk-python/cloudevents/sdk/converters/util.py
Lines 4 to 10 in b83bfc5
sdk-python/cloudevents/http/http_methods.py
Line 57 in b83bfc5
sdk-python/cloudevents/http/http_methods.py
Lines 64 to 67 in b83bfc5
I think that the solution might be as simple as changing all of the
and
s toor
s in thehas_binary_headers
method in step 4.Specifications
The text was updated successfully, but these errors were encountered: