You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Open a n x m spreadsheet (or create a new one)
PS: for simplicity, I'm assuming I'll be accessing a 2x2 spreadsheet
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.
Create a list containing the cells we changed.
PS: cells_to_update = [A1, B1, A2]
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"
}
}
The text was updated successfully, but these errors were encountered:
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
PS: for simplicity, I'm assuming I'll be accessing a 2x2 spreadsheet
PS: on my example, this means modifying only cells A1, B1 and A2.
PS: cells_to_update = [A1, B1, A2]
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"
}
}
The text was updated successfully, but these errors were encountered: