question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Batch updating cells can exceed quota for reading

See original GitHub issue

GitHub 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

  1. 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 )
  1. 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’”

  2. 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 runs self.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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ndevenishcommented, Aug 22, 2019

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 of Cell 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?

1reaction
burnashcommented, Mar 21, 2020

@taewookim correct,

Since #731 / v3.3.0 there are new methods for batch fetching or batch updating cell values:

Worksheet.batch_get()

Example:

worksheet.batch_get(['A1:B2', 'F12'])

– returns list of ValueRange objects (which are in turn lists of lists).

Worksheet.batch_update()

Example:

worksheet.batch_update([{
    'range': 'A1:B1',
    'values': [['42', '43']],
}, {
    'range': 'my_range',
    'values': [['44', '45']],
}])

In both examples worksheet is an instance of the Worksheet class.

More examples will follow in the docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quotas and limits | BigQuery
This document lists the quotas and limits that apply to BigQuery. A quota restricts how much of a particular shared Google Cloud resource...
Read more >
Quota exceeded for quota metric 'Write requests' and limit ...
I was making a project where we use a google sheet within that write one column value to another value. ... “Write Cell:...
Read more >
Usage limits | Google Sheets
Sheets API has per-minute quotas, and they're refilled every minute. For example, there's a read request limit of 300 per minute per project....
Read more >
Quota exceeded Sheets API write requests per minute. ...
In your situation, at Method: spreadsheets.values.batchUpdate, all requests for putting values to each sheet can be included in one request.
Read more >
Common error messages in Data Loader
Resolution: Reduce the Data Loader batch size to 1 in order to identify the problematic row(s). Check each instance of a column containing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found