File tree 1 file changed +12
-2
lines changed
src/python/google_cloud_utils
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -370,7 +370,7 @@ def insert(self, inserts):
370
370
A json explained here:
371
371
https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/insertAll
372
372
"""
373
- result = None
373
+ result = {}
374
374
for i in range (0 , len (inserts ), INSERT_BATCH_SIZE ):
375
375
response = self ._insert_batch (
376
376
inserts [i :min (len (inserts ), i + INSERT_BATCH_SIZE )])
@@ -379,8 +379,18 @@ def insert(self, inserts):
379
379
time .sleep (1 )
380
380
381
381
if not result :
382
+ # Use result from the first batch, appending errors from the rest.
382
383
result = response
383
384
else :
384
- result ['insertErrors' ].extend (response ['insertErrors' ])
385
+ # If there are new errors from the current batch, append to the result.
386
+ new_errors = response .get ('insertErrors' )
387
+ if not new_errors :
388
+ continue
389
+
390
+ # Apparently result may not have errors, be careful.
391
+ if result .get ('insertErrors' ):
392
+ result ['insertErrors' ].extend (new_errors )
393
+ else :
394
+ result ['insertErrors' ] = new_errors
385
395
386
396
return result
You can’t perform that action at this time.
0 commit comments