Repository navigation
Upload in-place edits of nested metadata - #454
Draft
shcheklein wants to merge 2 commits into
Draft
shcheklein wants to merge 2 commits into
shcheklein wants to merge 2 commits into
Conversation
PyDrive2 finds edits by comparing the file with a copy taken when Drive last answered. The copy shared nested values with the file, so an edit made in place, such as file["appProperties"]["stage"] = "done" or a changed entry in file["parents"], changed both, and Upload() sent nothing. The copy now has its own appProperties, properties, contentHints and parents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shcheklein
commented
Dec 3, 2026
shcheklein
commented
Dec 3, 2026
shcheklein
left a comment
Member
Author
There was a problem hiding this comment.
[AI generated — Copilot]
5-pass review summary: clean root-cause fix for shallow-copy aliasing. Minor gaps to check: contentRestrictions, avoiding copy.deepcopy on every listed file's parents, and covering parents.append(...) + ListFile() in tests.
contentRestrictions and downloadRestrictions are writable nested fields, so the saved copy gets its own copy of them. parents, properties and appProperties hold only strings, so a shallow copy is enough and keeps listings fast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the nested-metadata change-tracking update.
No open issues 🎉
What changed in this PR
Fixes PyDrive2’s metadata change tracking so Upload() detects in-place edits to writable nested fields without copying read-only fields.
Changes:
- Copies editable nested metadata when saving the clean state.
- Adds live regression tests for metadata edits, folder moves, and parent validation.
- Adds an offline test for uploading edited
contentHints.
| File | Description |
|---|---|
| pydrive2/test/test_files_unit.py | Tests uploads after in-place contentHints edits. |
| pydrive2/test/test_file.py | Tests nested edits, parent changes, and content unlocking against Drive. |
| pydrive2/files.py | Isolates editable nested fields in saved metadata snapshots. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changing a nested metadata value in place and then calling
Upload()sent nothing, and nothing said so.Example
Assigning a new value always worked, for example
file["appProperties"] = {**file["appProperties"], "stage": "done"}.Cause
To send only what changed, PyDrive2 compares the file with a copy taken when Drive last answered. The copy was shallow: a nested dict or list was the same object in both places. An edit in place changed both sides, so the comparison found no difference.
Fix
The copy now has its own copy of the nested fields that an upload can change:
appProperties,propertiesandparents(lists and dicts of strings, copied one level deep), andcontentHints,contentRestrictionsanddownloadRestrictions(dicts inside, copied in full). Other nested fields, such asownersorpermissions, stay shared: an upload cannot change them, so copying them would only cost memory.A default listing returns
parentswith every file, so each listed file keeps one more small list. Measured over 2,000 listed files: about 90 bytes more per file, from about 2,070 to 2,160 bytes.Appending a second parent in place (
file["parents"].append(...)) used to be ignored too. It now raises the error that assigning two parents already raised: a Drive v3 file has one parent.Validation
appProperties,propertiesorparents, edits the value in place and uploads. Drive then stores the new value, and forparentsthe file is in the new folder. The same holds forparentsof a file that came fromListFile(), and for unlocking a file by settingreadOnlyto false in its fetchedcontentRestrictions. These fail on main.ValueErrorbefore any request.contentHints: after an in-place edit ofcontentHints, the next upload sends them. It fails on main.🤖 Generated with Claude Code