-
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
KafkaConsumer always passes message key to deserializer, even if key is None #913
Comments
We generally wrap json.loads in a lambda to check for None. But I don't
think we can require that all deserializers map None -> None, however, so
we do not attempt to short circuit or special case internally.
…On Dec 18, 2016 3:50 PM, "Jeff Widman" ***@***.***> wrote:
I specified json.loads as the KafkaConsumer's key_deserializer callable,
then produced a message without a key.
json.loads throws an exception about expecting a string. Looks like root
cause is here: https://github.com/dpkp/kafka-python/blob/master/kafka/
consumer/fetcher.py#L546
Fetcher is always using passing the key to the deserializer, even if the
key is None.
Will submit a PR shortly.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#913>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAzetL_mOjJXDW2OLSh2JfRVdMteWxfZks5rJcangaJpZM4LQRat>
.
|
Thanks for the fast reply.
That makes sense.
Good suggestion, hadn't thought of that. I'm guessing you mean |
Are you open to adding a note about this lambda tip to the tutorial doc, so that others don't have to debug it? There's an example showing how to use the json.loads already, so just add another param on this line showing how to do this for keys with a comment like
|
Yes -- exactly. Although I agree that it is much more common to want None -> None, and much less common to want something else, I dont think we should make it impossible to do the latter. Options I think are ok: improve docs, provide a "stock" json deserializer, add a configuration to disable None skipping. Also you might want to take a quick look at #912 where I'm changing the internals of serializer / deserializer handling slightly. |
I specified
json.loads
as theKafkaConsumer
'skey_deserializer
callable, then produced a message without a key.json.loads
throws an exception about expecting a string. Looks like root cause is here: https://github.com/dpkp/kafka-python/blob/master/kafka/consumer/fetcher.py#L546Fetcher is always using passing the key to the deserializer, even if the key is
None
.Will submit a PR shortly.
The text was updated successfully, but these errors were encountered: