Skip to content

Kafka decoder treats structured events with ce_ headers as binary #338

Backlog

Description

@yumingjs

Expected Behavior

from_kafka_event should read the structured envelope when the content type identifies the supplied event format, even if Kafka headers repeat some event attributes. The Kafka binding, sections 3 and 3.3.3, permits this.

Actual Behavior

A single ce_subject header causes a validation error for missing source and type. If the headers repeat all required attributes, decoding succeeds but returns the whole envelope as event data.

Steps to Reproduce the Problem

from cloudevents.core.bindings.kafka import KafkaMessage, from_kafka_event

message = KafkaMessage(
    headers={"ce_subject": b"orders", "content-type": b"application/cloudevents+json"},
    key=None,
    value=(
        b'{"specversion":"1.0","source":"/test","type":"com.example.test",'
        b'"id":"123","subject":"orders","data":{"amount":5}}'
    ),
)
assert from_kafka_event(message).get_data() == {"amount": 5}

Specifications

Windows, Python 3.11.9, main at c932f0b. No Kafka broker is needed.

Thanks to @EmiRZx for pointing this out during the HTTP review. I have a Kafka-only fix and regression tests ready.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions