diff options
author | Jeff Tribble <jtribble@newrelic.com> | 2020-02-11 14:22:15 -0800 |
---|---|---|
committer | Jeff Widman <jeff@jeffwidman.com> | 2020-02-15 22:32:30 -0800 |
commit | 7195f0369c7dbe25aea2c3fed78d2b4f772d775b (patch) | |
tree | 2ccbbf005019ce5d587707c9c39f22122d90ee0b | |
parent | bbb8c90391e446de81833bc38dba4233a781fa5b (diff) | |
download | kafka-python-7195f0369c7dbe25aea2c3fed78d2b4f772d775b.tar.gz |
Fix topic error parsing in MetadataResponse
-rw-r--r-- | kafka/admin/client.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/kafka/admin/client.py b/kafka/admin/client.py index f71d9ef..7c1bd4f 100644 --- a/kafka/admin/client.py +++ b/kafka/admin/client.py @@ -373,14 +373,19 @@ class KafkaAdminClient(object): self._wait_for_futures([future]) response = future.value - # In Java, the error fieldname is inconsistent: + # In Java, the error field name is inconsistent: # - CreateTopicsResponse / CreatePartitionsResponse uses topic_errors # - DeleteTopicsResponse uses topic_error_codes - # So this is a little brittle in that it assumes all responses have - # one of these attributes and that they always unpack into - # (topic, error_code) tuples. - topic_error_tuples = (response.topic_errors if hasattr(response, 'topic_errors') - else response.topic_error_codes) + # - MetadataResponse uses topics[].error_code + topic_error_tuples = [] + if hasattr(response, 'topic_errors'): + topic_error_tuples.extend(response.topic_errors) + elif hasattr(response, 'topic_error_codes'): + topic_error_tuples.extend(response.topic_error_codes) + elif hasattr(response, 'topics'): + for topic in response.topics: + if hasattr(topic, 'topic') and hasattr(topic, 'error_code'): + topic_error_tuples.append((topic.topic, topic.error_code)) # 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 |