diff options
author | Dana Powers <dana.powers@gmail.com> | 2018-11-23 10:17:59 -0800 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2018-11-23 10:17:59 -0800 |
commit | 3260671cef403d88388f73fb2b94efd84958a30e (patch) | |
tree | d0887829711c564d74a4ce83734ac777184183e1 /kafka | |
parent | c6d8a536eff6e5ce205badc38b841d3bc27f40f6 (diff) | |
download | kafka-python-admin_client_unpack_errors.tar.gz |
Fix response error checking in KafkaAdminClient send_to_controlleradmin_client_unpack_errors
Diffstat (limited to 'kafka')
-rw-r--r-- | kafka/admin/client.py | 10 | ||||
-rw-r--r-- | kafka/protocol/admin.py | 2 |
2 files changed, 9 insertions, 3 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 diff --git a/kafka/protocol/admin.py b/kafka/protocol/admin.py index fc62c35..9f67af8 100644 --- a/kafka/protocol/admin.py +++ b/kafka/protocol/admin.py @@ -619,7 +619,7 @@ class CreatePartitionsResponse_v0(Response): API_VERSION = 0 SCHEMA = Schema( ('throttle_time_ms', Int32), - ('topic_errors', Array( + ('topic_error_codes', Array( ('topic', String('utf-8')), ('error_code', Int16), ('error_message', String('utf-8')))) |