Skip to content

Commit

Permalink
fix(producer): Pass headers as list (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
hairmare authored Dec 2, 2024
1 parent 11d286a commit 06d7562
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pathfinderevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pathfinderevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 06d7562

Please sign in to comment.