@@ -373,14 +373,19 @@ def _send_request_to_controller(self, request):
373373 self ._wait_for_futures ([future ])
374374
375375 response = future .value
376- # In Java, the error fieldname is inconsistent:
376+ # In Java, the error field name is inconsistent:
377377 # - CreateTopicsResponse / CreatePartitionsResponse uses topic_errors
378378 # - DeleteTopicsResponse uses topic_error_codes
379- # So this is a little brittle in that it assumes all responses have
380- # one of these attributes and that they always unpack into
381- # (topic, error_code) tuples.
382- topic_error_tuples = (response .topic_errors if hasattr (response , 'topic_errors' )
383- else response .topic_error_codes )
379+ # - MetadataResponse uses topics[].error_code
380+ topic_error_tuples = []
381+ if hasattr (response , 'topic_errors' ):
382+ topic_error_tuples .extend (response .topic_errors )
383+ elif hasattr (response , 'topic_error_codes' ):
384+ topic_error_tuples .extend (response .topic_error_codes )
385+ elif hasattr (response , 'topics' ):
386+ for topic in response .topics :
387+ if hasattr (topic , 'topic' ) and hasattr (topic , 'error_code' ):
388+ topic_error_tuples .append ((topic .topic , topic .error_code ))
384389 # Also small py2/py3 compatibility -- py3 can ignore extra values
385390 # during unpack via: for x, y, *rest in list_of_values. py2 cannot.
386391 # So for now we have to map across the list and explicitly drop any
0 commit comments