gspread icon indicating copy to clipboard operation
gspread copied to clipboard

del_worksheet doesn't translate the name to id

Open DawidKrysiak opened this issue 1 year ago • 1 comments

worksheet = sh.del_worksheet(value from variable holding the name of the worksheet)

error:

/lib/python3.8/site-packages/gspread/spreadsheet.py", line 436, in del_worksheet
    body = {"requests": [{"deleteSheet": {"sheetId": worksheet.id}}]}
AttributeError: 'str' object has no attribute 'id'

To Reproduce Steps to reproduce the behavior:

worksheet_name = 'something'
* sh = gc.open_by_url('https://docs.google.com/spreadsheets/d/<hash>')
* worksheet = sh.del_worksheet(worksheet_name)

Expected behavior spreadsheet.py should either obtain id if required, or documentation should specify the requirement of obtaining an id

Environment info:

  • Operating System: Ubuntu in WSL
  • Python version: Python 3.8.10
  • gspread version is: 5.4.0

DawidKrysiak avatar Aug 26 '22 07:08 DawidKrysiak

Hi this is expected.

As mentioned in the documentation this method expect a Worksheet instance.

See here: https://docs.gspread.org/en/latest/api/models/spreadsheet.html#gspread.spreadsheet.Spreadsheet.del_worksheet

What we can do is add a new method that expect: a worksheet ID, on one that expect a worksheet name (that might not work as worksheet names are not uniques).

lavigne958 avatar Aug 28 '22 07:08 lavigne958