From 06d756245f63cd5d851e6230cdd8a80fcba8e251 Mon Sep 17 00:00:00 2001 From: Lucas <116588+hairmare@users.noreply.github.com> Date: Mon, 2 Dec 2024 20:47:52 +0100 Subject: [PATCH] fix(producer): Pass headers as list (#198) --- pathfinderevents.py | 5 ++++- tests/test_pathfinderevents.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pathfinderevents.py b/pathfinderevents.py index b91d024..64ffdec 100644 --- a/pathfinderevents.py +++ b/pathfinderevents.py @@ -179,11 +179,14 @@ def _key_mapper(ce: CloudEvent) -> Any | None: # noqa: ANN401 ce, key_mapper=_key_mapper, ) + headers: list[tuple[str, bytes]] | None + if kafka_msg.headers: + headers = list(kafka_msg.headers.items()) self.producer.send( self.topic, key=kafka_msg.key, value=kafka_msg.value, - headers=kafka_msg.headers if kafka_msg.headers else None, + headers=headers, ).add_errback(on_send_error) self.producer.flush() logger.info( diff --git a/tests/test_pathfinderevents.py b/tests/test_pathfinderevents.py index fa2f32b..ceea6b9 100644 --- a/tests/test_pathfinderevents.py +++ b/tests/test_pathfinderevents.py @@ -106,7 +106,7 @@ def test_api_webhook(mock_producer, mock_api, mock_sys_exit): # noqa: ARG001 "test", key="ch.rabe.api.events.pathfinder.v0alpha1.OnAir.Klangbecken", value=ANY, - headers={"content-type": b"text/plain"}, + headers=[("content-type", b"text/plain")], ) value = json.loads(mock_producer.send.call_args.kwargs["value"]) assert value["data"] == "Klangbecken"