Skip to content

Commit

Permalink
Added raise of TypeError for non bytes key
Browse files Browse the repository at this point in the history
  • Loading branch information
se7entyse7en committed Nov 26, 2014
1 parent 664240a commit 2716d06
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kafka/producer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def send_messages(self, topic, partition, *msg):
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!")
Expand All @@ -180,7 +182,10 @@ def _send_messages(self, topic, partition, *msg, **kwargs):
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))
Expand Down

0 comments on commit 2716d06

Please sign in to comment.