nithinmurali / pygsheets

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

Fix append table #568

Closed Scmadar closed 1 year ago

Scmadar commented 1 year ago

As described in issues #561 and #563, the append_table function has been crashing in version 2.0.6. This is due to a change made for #546, to give the proper return value for this function (version 2.0.5 had no return value for append_table).

Instead of creating a GridRange using the JSON response text directly, e.g. "'Some Sheet'!A1:B4", split it apart and use the cell range only, e.g. "A1:B4". You don't need to add the worksheet name, because it's already being provided in self - and self comes with all sorts of goodies like the worksheet ID built in.

This appears to work correctly - the GridRange(s) created correctly link the worksheet, have the right worksheet ID and link to the overarching spreadsheet, etc. Confirmed it is working in a project, updating the range successfully and not throwing errors.

More testing may be needed in case the JSON response only returns the cell value, but I think Google is pretty good about sending the entire unambiguous range (including the sheet name).

Scmadar commented 1 year ago

My bad, does not fix #563 - that is a different error. Should resolve #561 though.

Scmadar commented 1 year ago

Added a separate fix for #563 - check for the key before adding that portion to the response.

Optionally, could still add the tableRange key with a null value. However, I would imagine that the returned value should mimic the Google response as closely as possible.

nithinmurali commented 1 year ago

Thank you for the PR. Looks good to me. However since this is a bugfix, could you please add a test here https://github.com/nithinmurali/pygsheets/blob/staging/tests/online_test.py#L261 to confirm that it indeed is working.

Scmadar commented 1 year ago

Added test for append_table. All 69 (nice) tests passing. Thanks!

nithinmurali commented 1 year ago

Awesome. looks Good!