diff --git a/src/python/google_cloud_utils/big_query.py b/src/python/google_cloud_utils/big_query.py index f56599b779d..e4a50431dad 100644 --- a/src/python/google_cloud_utils/big_query.py +++ b/src/python/google_cloud_utils/big_query.py @@ -383,16 +383,14 @@ def insert(self, inserts): if not result: # Use result from the first batch, appending errors from the rest. result = response - else: - # If there are new errors from the current batch, append to the result. - new_errors = response.get('insertErrors') - if not new_errors: - continue - - # Apparently result may not have errors, be careful. - if result.get('insertErrors'): - result['insertErrors'].extend(new_errors) - else: - result['insertErrors'] = new_errors + continue + + # If there are new errors from the current batch, append to the result. + new_errors = response.get('insertErrors') + if not new_errors: + continue + + # Apparently result may not have errors, use |setdefault| to be careful. + result.setdefault('insertErrors', []).extend(new_errors) return result