Skip to content

Fix topic error parsing in MetadataResponse #1997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions kafka/admin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,19 @@ def _send_request_to_controller(self, request):
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
Expand Down