summaryrefslogtreecommitdiff
path: root/kafka/admin
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2018-11-23 10:17:59 -0800
committerDana Powers <dana.powers@gmail.com>2018-11-23 10:17:59 -0800
commit3260671cef403d88388f73fb2b94efd84958a30e (patch)
treed0887829711c564d74a4ce83734ac777184183e1 /kafka/admin
parentc6d8a536eff6e5ce205badc38b841d3bc27f40f6 (diff)
downloadkafka-python-admin_client_unpack_errors.tar.gz
Fix response error checking in KafkaAdminClient send_to_controlleradmin_client_unpack_errors
Diffstat (limited to 'kafka/admin')
-rw-r--r--kafka/admin/client.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/kafka/admin/client.py b/kafka/admin/client.py
index e25afe7..9b95ffd 100644
--- a/kafka/admin/client.py
+++ b/kafka/admin/client.py
@@ -331,8 +331,14 @@ class KafkaAdminClient(object):
while tries:
tries -= 1
response = self._send_request_to_node(self._controller_id, request)
- # DeleteTopicsResponse returns topic_error_codes rather than topic_errors
- for topic, error_code in getattr(response, "topic_errors", response.topic_error_codes):
+ # This is a little brittle in that it assumes all responses have the
+ # same "error" attribute (topic_error_codes) and that it always
+ # unpacks into (topic, error_code) tuples.
+ # Also small py2/py3 compatibility -- py3 can ignore extra values
+ # during unpack via: for x, y, *rest in list_of_values. py2 cannot.
+ # So for now we have to map across the list and explicitly drop any
+ # extra values (ususally the error_message)
+ for topic, error_code in map(lambda e: e[:2], response.topic_error_codes):
error_type = Errors.for_code(error_code)
if tries and isinstance(error_type, NotControllerError):
# No need to inspect the rest of the errors for