Skip to content

Fix Worksheet.batch_update mutating input data in place - #1604

Open
DYNOSuprovo wants to merge 1 commit into
burnash:masterfrom
DYNOSuprovo:fix/batch-update-mutate-input-1601
Open

DYNOSuprovo wants to merge 1 commit into
burnash:masterfrom
DYNOSuprovo:fix/batch-update-mutate-input-1601

Conversation

@DYNOSuprovo

Copy link
Copy Markdown

Summary

Fixes #1601.

Problem

Worksheet.batch_update previously mutated the caller's input dictionaries in-place when converting "range" to an absolute range name:

for values in data:
    values["range"] = absolute_range_name(self.title, values["range"])

If a caller reuses the same data list across calls or retries worksheet.batch_update(data) after a transient failure (as reported in #1601), the worksheet title is prepended repeatedly ('Sheet1'!'Sheet1'!'Sheet1'!A1:B2), resulting in an APIError: [400]: Unable to parse range. Additionally, if data is a single-pass iterator (Iterable), the in-place loop exhausts it before constructing body.

Solution

  • Build a new list of shallow-copied dictionaries with the absolutized "range" ([{**values, "range": absolute_range_name(self.title, values["range"])} for values in data]), matching the non-mutating pattern used in Worksheet.get, Worksheet.batch_get, and Worksheet.batch_clear.
  • Update WorksheetTest.test_batch_update to verify that the caller's input dictionaries are not mutated in-place.

Signed-off-by: DYNOSuprovo <DYNOSuprovo@users.noreply.github.com>
@bensynapse bensynapse mentioned this pull request Oct 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Imposible Parse Range

1 participant