From 1a31be52ec012dfa0ef5079ff9982e01408a8fe1 Mon Sep 17 00:00:00 2001 From: Jeff Widman Date: Mon, 7 Jan 2019 12:57:25 -0800 Subject: 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 --- kafka/admin/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'kafka') 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 -- cgit v1.2.1