Skip to content

Commit 1a31be5

Browse files
committed
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
1 parent d2f9413 commit 1a31be5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kafka/admin/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ def _send_request_to_controller(self, request):
337337
# So this is a little brittle in that it assumes all responses have
338338
# one of these attributes and that they always unpack into
339339
# (topic, error_code) tuples.
340-
topic_error_tuples = getattr(response, "topic_errors", response.topic_error_codes)
340+
topic_error_tuples = (response.topic_errors if hasattr(response, 'topic_errors')
341+
else response.topic_error_codes)
341342
# Also small py2/py3 compatibility -- py3 can ignore extra values
342343
# during unpack via: for x, y, *rest in list_of_values. py2 cannot.
343344
# So for now we have to map across the list and explicitly drop any

0 commit comments

Comments
 (0)