summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2018-03-10 10:27:05 -0500
committerGitHub <noreply@github.com>2018-03-10 10:27:05 -0500
commitb8d40b52b4142b97a8797d809cc3b042cec4877f (patch)
treeb1bf63dc9634b668db025360678e753fd22bd6bc
parent22e3f75e92a791b3a42cac2a87b19ec33a4ca351 (diff)
downloadkafka-python-b8d40b52b4142b97a8797d809cc3b042cec4877f.tar.gz
Validate that serializers generate bytes-like (or None) data (#1420)
-rw-r--r--kafka/producer/kafka.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/kafka/producer/kafka.py b/kafka/producer/kafka.py
index 52c0953..f285ab4 100644
--- a/kafka/producer/kafka.py
+++ b/kafka/producer/kafka.py
@@ -540,8 +540,6 @@ class KafkaProducer(object):
assert not (value is None and key is None), 'Need at least one: key or value'
key_bytes = value_bytes = None
try:
- # first make sure the metadata for the topic is
- # available
self._wait_on_metadata(topic, self.config['max_block_ms'] / 1000.0)
key_bytes = self._serialize(
@@ -550,6 +548,9 @@ class KafkaProducer(object):
value_bytes = self._serialize(
self.config['value_serializer'],
topic, value)
+ assert type(key_bytes) in (bytes, bytearray, memoryview, type(None))
+ assert type(value_bytes) in (bytes, bytearray, memoryview, type(None))
+
partition = self._partition(topic, partition, key, value,
key_bytes, value_bytes)