Batch updating cells can exceed quota for reading
See original GitHub issueGitHub Issues are for bugs and feature requests.
Environment info
Operating System: Mac OS X 10.11.6 Python version: 2.7.14 gspread version: 3.0.1
Steps to reproduce
- Use code similar to what is shown in the Docs under Updating Cells
Within a loop where I’m looking for cells to update, add any to a list:
if needs_update == True:
updated_cell = wks.cell( row_num, col_num )
updated_cell.value = new_valuer
cells_to_update.append( updated_cell )
At the end of the script, I will send the list to be batch updated:
wks.update_cells( cells_to_update )
-
The problem occurs BEFORE I get to the
update_cells()
call. I get a “code 429” and “Quota exceeded for quota group ‘ReadGroup’ and limit ‘USER-100s’ of service ‘sheets.googleapis.com’” -
I believe what’s happening is that every time I try to fetch a cell instance by doing
updated_cell = wks.cell( row_num, col_num )
, the.cell()
method runsself.spreadsheet.values_get()
, which results in an API call.
So, if I’m understanding this correctly, for every cell I want to update, I will have to make one API call to read its value. Hundreds of cells to update? Hundreds of API calls to read. All these API calls at once causes me to exceed the “ReadGroup” quota limit.
Is there a way to suppress this? A way to get a Cell instance without an API call? Or perhaps a way to batch read a list of cells in one API call?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:13 (3 by maintainers)
Top GitHub Comments
I think I’ve got this same need, also ran into read quota throttles when repeatedly calling
.get_cell
. I then was going to try building a list ofCell
objects to pass to update cells but thanks to this thread know that apparently behaves unexpectedly.I’ve avoided repeated reads by reading the whole sheet at once, but want to update an effectively random sample of cells that may or may not be partially contiguous - I’d also like to avoid just bulk updating the whole sheet for versioning if possible, unless that’s the right way to approach this.
@Kirkman’s modification seems to work for what I need; one call updating lots of disparate things. Is this a good way to approach the problem or is there a better way to do it?
Should we be putting together a pull request for this?
@taewookim correct,
Since #731 / v3.3.0 there are new methods for batch fetching or batch updating cell values:
Worksheet.batch_get()
Example:
– returns list of
ValueRange
objects (which are in turn lists of lists).Worksheet.batch_update()
Example:
In both examples
worksheet
is an instance of theWorksheet
class.More examples will follow in the docs.