Skip to content

Commit c704120

Browse files
authored
None data fix (cloudevents#78)
* fixed none data issue Signed-off-by: Curtis Mason <cumason@google.com> * added none data test for marshalling Signed-off-by: Curtis Mason <cumason@google.com> * lint fix Signed-off-by: Curtis Mason <cumason@google.com>
1 parent 7437ea4 commit c704120

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cloudevents/sdk/http/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
def default_marshaller(content: any):
27-
if len(content) == 0:
27+
if content is None or len(content) == 0:
2828
return None
2929
try:
3030
return json.dumps(content)

cloudevents/tests/test_http_events.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,16 @@ def test_cloudevent_repr(specversion):
401401
# we had issues in the past where event.__repr__() could run but
402402
# print(event) would fail.
403403
print(event)
404+
405+
406+
@pytest.mark.parametrize("specversion", ["1.0", "0.3"])
407+
def test_none_data_cloudevent(specversion):
408+
event = CloudEvent(
409+
{
410+
"source": "<my-url>",
411+
"type": "issue.example",
412+
"specversion": specversion,
413+
}
414+
)
415+
to_binary_http(event)
416+
to_structured_http(event)

0 commit comments

Comments
 (0)