Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIError thrown when trying to write on subarea of spreadsheet #547

Open
cristiannomartins opened this issue May 14, 2018 · 2 comments
Open
Labels

Comments

@cristiannomartins
Copy link

Apparently, there is a couple of bugs on calculating the range of cells that need to be updated through update_cells. First of all, it assumes the cells are sorted and only the first and last cells are important to calculate the range. Depending on how someone needs to go through the data, this is not always the case.

Second, if someone does not need to write over the whole table, say you write on n cells in the first column but on the first n-1 for all others, the range can be miscalculated and an API error will be thrown.

Environment info

Operating System: Ubuntu 18.04 LTS
Python version: 3.6.5
gspread version: ?? (latest from pip)

Steps to reproduce

  1. Open a n x m spreadsheet (or create a new one)
    PS: for simplicity, I'm assuming I'll be accessing a 2x2 spreadsheet
  2. Modify values from cells that are only in or above the secondary diagonal of the spreadsheet.
    PS: on my example, this means modifying only cells A1, B1 and A2.
  3. Create a list containing the cells we changed.
    PS: cells_to_update = [A1, B1, A2]
  4. Call update_cells on that list created on step 3.
    PS: range is calculated as "worksheet!A1:A2". Notice that, even if I sort the list as [A1, A2, B1] this will still be an issue, since the new range will be A1:B1, which does not include A2.

Stack trace or other output that would be helpful

Traceback (most recent call last):
File "/home/user/triangle.py", line 360, in
main()
File "/home/user/triangle.py", line 271, in write_to_sheet
sheet.update_cells(cells_to_update)
File "/home/user/.local/lib/python3.6/site-packages/gspread/models.py", line 609, in update_cells
'values': values_rect
File "/home/user/.local/lib/python3.6/site-packages/gspread/models.py", line 115, in values_update
r = self.client.request('put', url, params=params, json=body)
File "/home/user/.local/lib/python3.6/site-packages/gspread/client.py", line 79, in request
raise APIError(response)
gspread.exceptions.APIError: {
"error": {
"code": 400,
"message": "Requested writing within range ['Test-0'!A1:B1], but tried writing to row [2]",
"status": "INVALID_ARGUMENT"
}
}

@muddi900
Copy link
Contributor

Hey

did you ever find the solution to the issue?

thanks

@burnash
Copy link
Owner

burnash commented Apr 27, 2020

@muddi900 Could you post your code example and a stack trace?

@burnash burnash added the TTL label Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants