-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set length of header value to 0 if None #2004
Conversation
When this fix isn't in, what happens? Do you get a |
Indeed I get an |
I think this is probably good to merge, but first I'd appreciate if you can post a stacktrace when you get into the office on Monday... I just want to see the code flow here to doublecheck. |
@jeffwidman Seems legit, it's not possible with kafka-python, because we explicitly assert types in headers, but if I send the message from aiokafka and try to get it using Kafka-Python it is possible to get this behaviour: Producer: from aiokafka import AIOKafkaProducer
import asyncio
loop = asyncio.get_event_loop()
async def send_one():
producer = AIOKafkaProducer(
loop=loop, bootstrap_servers='localhost:9092')
# Get cluster layout and topic/partition allocation
await producer.start()
try:
# Produce messages
res = await producer.send_and_wait(
"test-topic", b"Super message", headers=[("header", None)])
print(res)
finally:
await producer.stop()
loop.run_until_complete(send_one()) Consumer: from kafka import KafkaConsumer
cc = KafkaConsumer(bootstrap_servers="localhost:9092")
cc.subscribe(["test-topic"])
for msg in cc:
print(msg) From the Kafka protocol perspective, this is a valid case, as BYTES can be encoded using null string and value is defined as BYTES. Keys should not be a problem, as it is not correct to have null strings. See https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/header/internals/RecordHeader.java - it defines a strict requirement for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM -- thanks!
Here you go:
And here's the debugged headers variable:
|
Thanks @tvoinarovskyi for this research. That was the crux of what I was wondering... should we be preventing this from ever being |
This pull request adds a check when consuming messages containing a header whose value is None. In that case, it sets the length to 0.
This change is