gspread icon indicating copy to clipboard operation
gspread copied to clipboard

Adding new rows doesn't increase row count property

Open cgmorton opened this issue 6 years ago • 10 comments

Environment info

Operating System: MacOS Sierra Python version: 3.6.3 (Miniconda) gspread version: 3.0.0

Steps to reproduce

ws = sheet.worksheet('Sheet1') print(ws.row_count) ws.add_rows(1) print(ws.row_count)

cgmorton avatar May 04 '18 06:05 cgmorton

I too am having this issue if anyone can lend a hand

uneasyguy avatar May 08 '18 11:05 uneasyguy

The issue is actually larger than that - the Worksheet instance seems to never update its properties after changing them, the same goes for self.col_count and self.title properties.

I think the issue could be fixed by updating the Worksheet instance properties every time after calling self.spreadsheet.batch_update()

crash5936 avatar May 16 '18 09:05 crash5936

You're right! Let me know if it would help if I modified the title of this issue to better describe the problem. Or I could close this issue if you want to start a new one.

cgmorton avatar May 16 '18 13:05 cgmorton

I tried fixing the issue and opened a pull request, it fixed all the issues for me, let's see if it's viable and we can get this merged into master :)

crash5936 avatar May 16 '18 13:05 crash5936

I'm wondering if there is a resolution to this issue yet?

jasontsp avatar Jan 14 '19 19:01 jasontsp

I tried fixing the issue and opened a pull request, it fixed all the issues for me, let's see if it's viable and we can get this merged into master :)

I would love to see this one merged

patrickloeber avatar May 10 '20 11:05 patrickloeber

Any updates on this? This is a pretty big impediment for us right now.

tlhinman avatar Jan 11 '21 22:01 tlhinman

Can't you just bypass the issue with saving row_count into a variable before appending and then incrementing it everytime you append a row during the code afterwards? Works fine for me at least

Acendro avatar Jan 29 '21 14:01 Acendro

Hi this is a bigger issue in fact, as none of the properties are up to date after changing them.

I think the simplest way of solving this for now is to update local properties when an update is successful. So for instance calling add_rows will increase the local row_count value. this can lead to mistakes still because someone could be updating the sheet from an other script or from a web browser. but still it solves the issue for single access.

lavigne958 avatar May 24 '21 09:05 lavigne958

I have the same problem like issue starter.

kuznetsov-m avatar Apr 05 '22 13:04 kuznetsov-m

Fixed by #1211?

alifeee avatar Jun 08 '23 17:06 alifeee

yes closed by #1211

lavigne958 avatar Jun 14 '23 13:06 lavigne958

this specific method is fixed, but there is still the same issue if you use other methods such as append_rows or insert_rows

see https://github.com/burnash/gspread/issues/881#issuecomment-1591337773

alifeee avatar Jun 14 '23 14:06 alifeee