Skip to content

Commit cb6d561

Browse files
committed
refine bug fix
1 parent b6040a5 commit cb6d561

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

kafka/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ def _iter_broker_errors():
226226

227227

228228
def check_error(response):
229+
if isinstance(response, Exception):
230+
raise response
229231
if response.error:
230232
error_class = kafka_errors.get(response.error, UnknownError)
231233
raise error_class(response)

kafka/consumer/simple.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,6 @@ def _fetch(self):
343343
for resp in responses:
344344

345345
try:
346-
if isinstance(resp, Exception):
347-
raise resp
348346
check_error(resp)
349347
except (UnknownTopicOrPartitionError, NotLeaderForPartitionError):
350348
self.client.reset_topic_metadata(resp.topic)
@@ -357,12 +355,12 @@ def _fetch(self):
357355
# Retry this partition
358356
retry_partitions[resp.partition] = partitions[resp.partition]
359357
continue
360-
except FailedPayloadsError:
358+
except FailedPayloadsError as e:
361359
log.warning("Failed payloads of %s"
362360
"Resetting partition offset...",
363-
resp.failed_payloads)
361+
e.payload)
364362
# Retry this partition
365-
retry_partitions[resp.failed_payloads.partition] = partitions[resp.failed_payloads.partition]
363+
retry_partitions[e.payload.partition] = partitions[e.payload.partition]
366364
continue
367365

368366
partition = resp.partition

test/test_failover_integration.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ def test_switch_leader_keyed_producer(self):
169169
msg = random_string(10).encode('utf-8')
170170
producer.send_messages(topic, key, msg)
171171

172+
@kafka_versions("all")
173+
def test_switch_leader_simple_consumer(self):
174+
producer = Producer(self.client, async=True)
175+
consumer = SimpleConsumer(self.client, None, self.topic, partitions=None, auto_commit=False, iter_timeout=10)
176+
self._send_random_messages(producer, self.topic, 0, 2)
177+
consumer.get_messages()
178+
self._kill_leader(self.topic, 0)
179+
consumer.get_messages()
172180

173181
def _send_random_messages(self, producer, topic, partition, n):
174182
for j in range(n):

0 commit comments

Comments
 (0)