summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Widman <jeff@jeffwidman.com>2019-01-07 12:57:25 -0800
committerJeff Widman <jeff@jeffwidman.com>2019-01-07 12:57:25 -0800
commit1a31be52ec012dfa0ef5079ff9982e01408a8fe1 (patch)
tree2329cc32638474edf4790226b56424ef2d535cf6
parentd2f9413b0311e6ec4d782cf9983f61c9f258cc7b (diff)
downloadkafka-python-1a31be52ec012dfa0ef5079ff9982e01408a8fe1.tar.gz
Fix `AttributeError` caused by `getattr()`
`getattr(object, 'x', object.y)` will evaluate the default argument `object.y` regardless of whether `'x'` exists. For details see: https://stackoverflow.com/q/31443989/770425
-rw-r--r--kafka/admin/client.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/kafka/admin/client.py b/kafka/admin/client.py
index bd173b9..d02a68a 100644
--- a/kafka/admin/client.py
+++ b/kafka/admin/client.py
@@ -337,7 +337,8 @@ class KafkaAdminClient(object):
# 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 = getattr(response, "topic_errors", response.topic_error_codes)
+ topic_error_tuples = (response.topic_errors if hasattr(response, 'topic_errors')
+ else response.topic_error_codes)
# 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