summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2018-03-07 17:07:09 -0800
committerGitHub <noreply@github.com>2018-03-07 17:07:09 -0800
commita6130d288f84af7ffe054bdf301bc40febe07719 (patch)
tree478156450f86bf3342f459ea8ee3c488ffa21cdd
parentff13f872f4a517c341cd84db89111dcbdf642b60 (diff)
downloadkafka-python-a6130d288f84af7ffe054bdf301bc40febe07719.tar.gz
Use local copies in Fetcher._fetchable_partitions to avoid mutation errors (#1400)
-rw-r--r--kafka/consumer/fetcher.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/kafka/consumer/fetcher.py b/kafka/consumer/fetcher.py
index 4f2a543..ea7d5d8 100644
--- a/kafka/consumer/fetcher.py
+++ b/kafka/consumer/fetcher.py
@@ -626,9 +626,12 @@ class Fetcher(six.Iterator):
def _fetchable_partitions(self):
fetchable = self._subscriptions.fetchable_partitions()
- if self._next_partition_records:
- fetchable.discard(self._next_partition_records.topic_partition)
- for fetch in self._completed_fetches:
+ # do not fetch a partition if we have a pending fetch response to process
+ current = self._next_partition_records
+ pending = copy.copy(self._completed_fetches)
+ if current:
+ fetchable.discard(current.topic_partition)
+ for fetch in pending:
fetchable.discard(fetch.topic_partition)
return fetchable