nithinmurali / pygsheets

Google Sheets Python API v4
https://pygsheets.readthedocs.io/en/latest
Other
1.5k stars 220 forks source link

append_table constantly crash #561

Closed ossipsasha closed 1 year ago

ossipsasha commented 1 year ago

Describe the bug append_table crash with exception.

I have regular code which deletes data from spreadsheet with multiple deletes and append new data. Append stopped to work starting version 2.0.6 As I understand it is because of https://github.com/nithinmurali/pygsheets/issues/546

To Reproduce Try to append data to regular table with data.

credentials = Credentials.from_authorized_user_file(
    credentials_path, scopes=pygsheets.authorization._SCOPES)
gc = pygsheets.authorize(credentials=credentials)
sh = gc.open_by_key(my_key)

# it was in my code, but should not cause the issue
# col = wks.get_col(0)
# wks.delete_rows(my_row, my_count)

wks = sh.worksheet_by_title("My Data")
wks.append_table(values=my_data)

# see error
  File "/usr/local/lib/python3.11/site-packages/pygsheets/utils.py", line 214, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pygsheets/worksheet.py", line 1148, in append_table
    'tableRange': GridRange.create(response_json['tableRange'], self),
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pygsheets/address.py", line 374, in create
    grange = GridRange(label=data, worksheet=wks)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pygsheets/address.py", line 259, in __init__
    self._calculate_addresses(label)
  File "/usr/local/lib/python3.11/site-packages/pygsheets/address.py", line 449, in _calculate_addresses
    self.worksheet_title = label.split('!')[0]
    ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pygsheets/address.py", line 359, in worksheet_title
    raise InvalidArgumentValue("This range already has a worksheet with different title set.")
pygsheets.exceptions.InvalidArgumentValue: This range already has a worksheet with different title set.

System Information

nithinmurali commented 1 year ago

@ossipsasha will try to reproduce this and issue a hotfix. Please use 2.0.5 until fix is deployed.

nithinmurali commented 1 year ago

@Scmadar 's MR fixed this.