cloudevents / sdk-python

Python SDK for CloudEvents
https://pypi.org/p/cloudevents/
Apache License 2.0
279 stars 55 forks source link

to_structured for Kafka does not create ce_ prefixed headers #238

Closed christianplatta1012 closed 3 months ago

christianplatta1012 commented 3 months ago

Expected Behavior

According to the 1.0 specification all CloudEvent attributes should be included as header values in a Kafka message with a ce_ prefix. https://github.com/cloudevents/spec/blob/v1.0/kafka-protocol-binding.md#3231-property-names I would expect that the to_structured function. in cloudevents.kafka.conversion should be doing this.

Actual Behavior

Instead all attributes are added to the message value json and the headers are empty. If I look into the source code attributes are never getting mapped into headers at all (with or without prefix)

Steps to Reproduce the Problem

from cloudevents.http import CloudEvent from cloudevents.kafka.conversion import to_structured

def test_kafka_cloud_event(): attributes = { "specversion": "1.0", "type": "topic", "source": "source", "contenttype": "application/json", } event = CloudEvent(attributes, {"key": "value"}) kafka_message = to_structured(event) print(kafka_message) print(kafka_message.headers) print(kafka_message.key) print(kafka_message.value) assert "ce_specversion" in kafka_message.headers

Specifications

xSAVIKx commented 3 months ago

Hey @christianplatta1012. Thx for opening the issue.

I believe you're referring to binary part of the spec while using to_structured (i.e. structured) conversion.

We do have a test case that covers the binary headers:

https://github.com/cloudevents/sdk-python/blob/16441d79f433f98403e327e4015378be25f3b457/cloudevents/tests/test_kafka_conversions.py#L117C9-L130

If you believe that there still is an issue can you please provide an example of using respective conversion mode that is behaving wrongly or is not covered.

christianplatta1012 commented 3 months ago

That was what I was looking for, thank you!