diff options
author | Lou Marvin Caraig <loumarvincaraig@gmail.com> | 2014-11-26 13:05:23 +0100 |
---|---|---|
committer | Lou Marvin Caraig <loumarvincaraig@gmail.com> | 2014-11-26 15:04:28 +0100 |
commit | 2716d06ea01edc07a52ffb6a645b4b331965b781 (patch) | |
tree | 3fda5683c429810a1a95fe5039ef2cb64626c631 | |
parent | 664240ab4dd846c63efa58b210d4832f88446bf6 (diff) | |
download | kafka-python-2716d06ea01edc07a52ffb6a645b4b331965b781.tar.gz |
Added raise of TypeError for non bytes key
-rw-r--r-- | kafka/producer/base.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/kafka/producer/base.py b/kafka/producer/base.py index 7f9b18c..6e19b92 100644 --- a/kafka/producer/base.py +++ b/kafka/producer/base.py @@ -172,6 +172,8 @@ class Producer(object): return self._send_messages(topic, partition, *msg) def _send_messages(self, topic, partition, *msg, **kwargs): + key = kwargs.pop('key', None) + # Guarantee that msg is actually a list or tuple (should always be true) if not isinstance(msg, (list, tuple)): raise TypeError("msg is not a list or tuple!") @@ -180,7 +182,10 @@ class Producer(object): if any(not isinstance(m, six.binary_type) for m in msg): raise TypeError("all produce message payloads must be type bytes") - key = kwargs.pop('key', None) + # Raise TypeError if the key is not encoded as bytes + if key is not None and not isinstance(key, six.binary_type): + raise TypeError("the key must be type bytes") + if self.async: for m in msg: self.queue.put((TopicAndPartition(topic, partition), m, key)) |