Skip to content

Conversation

Bazarovinc
Copy link

@Bazarovinc Bazarovinc commented Aug 15, 2025

This PR addresses the UnicodeDecodeError that occurred when processing Kafka messages containing headers with non-UTF-8 byte sequences

Fixes #2458, FIxes #2214

Type of change

  • Bug fix (a non-breaking change that resolves an issue)

Checklist

  • My code adheres to the style guidelines of this project (just lint shows no errors)
  • I have conducted a self-review of my own code
  • I have made the necessary changes to the documentation
  • My changes do not generate any new warnings
  • I have added tests to validate the effectiveness of my fix or the functionality of my new feature
  • Both new and existing unit tests pass successfully on my local environment by running just test-coverage
  • I have ensured that static analysis tests are passing by running just static-analysis
  • I have included code examples to illustrate the modifications

@Bazarovinc Bazarovinc requested a review from Lancetnik as a code owner August 15, 2025 13:53
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Nikita Veselenko seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot added Confluent Issues related to `faststream.confluent` module AioKafka Issues related to `faststream.kafka` module labels Aug 15, 2025
@Bazarovinc Bazarovinc changed the base branch from dev to main August 15, 2025 14:09
@draincoder
Copy link
Collaborator

@Bazarovinc Please look at this #2214 issue as well and add comprehensive tests.

@Lancetnik Lancetnik changed the base branch from main to dev August 15, 2025 18:26
@Bazarovinc Bazarovinc marked this pull request as draft August 16, 2025 08:30
@Bazarovinc
Copy link
Author

@draincoder Here’s a preliminary implementation for handling Kafka message headers. Please review and let me know if this approach looks good or if any adjustments are needed.

@Lancetnik Lancetnik changed the base branch from dev to main September 4, 2025 20:51
Comment on lines +34 to +36
headers.get("reply_to"),
headers.get("content-type"),
headers.get("correlation_id"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does headers.get return? Can you show example or write type?

reply_to=headers.get("reply_to", ""),
content_type=headers.get("content-type"),
reply_to=headers.get("reply_to").decode()
if "content-type" in headers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content-type -> reply_to

Comment on lines +79 to +88
reply_to=headers.get("reply_to").decode()
if "content-type" in headers
else None,
content_type=headers.get("content-type").decode()
if "content-type" in headers
else None,
message_id=f"{first.offset()}-{last.offset()}-{first_timestamp}",
correlation_id=headers.get("correlation_id"),
correlation_id=headers.get("correlation_id").decode()
if "correlation_id" in headers
else None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do u this about this way for better readable:

reply_to=headers.get("reply_to", b"").decode() or None
content_type=headers.get("content-type", b"").decode() or None
correlation_id=headers.get("correlation_id", b"").decode() or None

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

Labels

AioKafka Issues related to `faststream.kafka` module Confluent Issues related to `faststream.confluent` module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug:FastStream fails to decode non-UTF-8 Kafka message headers Feature: allow defining kafka headers as bytes

4 participants