summaryrefslogtreecommitdiff
path: root/kafka/producer/base.py
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2015-12-02 12:49:49 -0800
committerDana Powers <dana.powers@gmail.com>2015-12-02 12:49:49 -0800
commit0d41e6b07ea16b1074d3a63d521747361f1c7145 (patch)
tree1889ef033e0f0270252bc608b466add391ed42bc /kafka/producer/base.py
parente99a934bab1d551d07dd0c6365f6a730028489f3 (diff)
parent3fbd1cc80965a0f49bfd6c505a1c021af95354fb (diff)
downloadkafka-python-0d41e6b07ea16b1074d3a63d521747361f1c7145.tar.gz
Merge pull request #409 from scrapinghub/feature-allow-null-payload
Allow null payload for deletion feature
Diffstat (limited to 'kafka/producer/base.py')
-rw-r--r--kafka/producer/base.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/kafka/producer/base.py b/kafka/producer/base.py
index 3c826cd..d5c013a 100644
--- a/kafka/producer/base.py
+++ b/kafka/producer/base.py
@@ -355,9 +355,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(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):