diff options
author | Viktor Shlapakov <vshlapakov@gmail.com> | 2015-06-17 14:05:05 +0300 |
---|---|---|
committer | Viktor Shlapakov <vshlapakov@gmail.com> | 2015-06-17 14:05:05 +0300 |
commit | a943eb3bedc94366dff34bfe0fcc8c6484adb2d1 (patch) | |
tree | 99c0c000807229ee78565569c5004b99811e4003 | |
parent | 99998af7ed66b3ddb8cb134fc047524dbe074698 (diff) | |
download | kafka-python-a943eb3bedc94366dff34bfe0fcc8c6484adb2d1.tar.gz |
Exclude (null,null) pair for producer
-rw-r--r-- | kafka/producer/base.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/kafka/producer/base.py b/kafka/producer/base.py index 00e1d13..bee1888 100644 --- a/kafka/producer/base.py +++ b/kafka/producer/base.py @@ -354,9 +354,15 @@ class Producer(object): if not isinstance(msg, (list, tuple)): raise TypeError("msg is not a list or tuple!") - # Raise TypeError if any message is not encoded as bytes - if any(m is not None and not isinstance(m, six.binary_type) for m in msg): - raise TypeError("all produce message payloads must be type bytes") + for m in msg: + # The protocol allows to have key & payload with null values both, + # (https://goo.gl/o694yN) but having (null,null) pair doesn't make sense. + if m is None: + if key is None: + raise TypeError("key and payload can't be null in one") + # Raise TypeError if any non-null message is not encoded as bytes + elif not isinstance(m, six.binary_type): + raise TypeError("all produce message payloads must be null or type bytes") # Raise TypeError if topic is not encoded as bytes if not isinstance(topic, six.binary_type): |