Fixing FilePad.update_file()#574
Open
yeyuan98 wants to merge 2 commits into
Open
Conversation
- Add missing self.filepad.update_one() call in _update_file_contents to persist gfs_id and compressed changes to MongoDB after update - Reorder _update_file_contents to insert new file before deleting old GridFS entry, preventing data loss on write failure - Fix file handle leak by using `with open()` context manager - Wrap gfs_id with ObjectId() in delete_file_by_id for proper GridFS deletion (string vs ObjectId mismatch) - Fix from_db_file() passing `database=` instead of `name=` to __init__, which caused TypeError on every call - Fix zlib.compress() receiving boolean as compression level instead of using the default level (6) - Update tests with round-trip assertions to verify data persistence after update_file and update_file_by_id
- Add summary line to _update_file_contents and delete_file_by_id docstrings (previously had only Args blocks, no description) - Add "Updating files" section to FilePad tutorial covering update_file() and update_file_by_id() - Fix tutorial intro to mention "update" alongside add/delete, consistent with the module-level docstring
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.
Note: This bug fix was created with help of coding agents. Would greatly appreciate any feedback & happy to make further changes.
Summary
FilePad.update_file()andFilePad.update_file_by_id()are broken on main, causing the following problems:This PR includes fixes and documentation updates to correct bugs in the file update feature of FilePad.
Issue list
_update_file_contents()never callsupdate_one()to persist the newgfs_idto MongoDBget_file()always returns old contentfrom_db_file()passesdatabase=to__init__(), but the parameter is namednameTypeError—from_db_file()is unusable_update_file_contents()deletes old GridFS entry before writing the new onegridfs.delete()called with stringgfs_idinstead ofObjectIdzlib.compress(contents, compress)passes booleanTrueas compression levelopen(path, read_mode).read()in_update_file_contentsnever closes the file handleFix list
fireworks/utilities/filepad.py(lines 257, 304, 334–342, 375):delete_file_by_id): Wrapgfs_idwithObjectId()for proper GridFS deletion._insert_to_gridfs): Remove booleancompressargument fromzlib.compress()call, using the default level 6._update_file_contents): Three fixes applied together:with open()context manager to prevent file handle leak.self.filepad.update_one()call to persist the newgfs_idandcompressedflag to MongoDB.from_db_file): Renamedatabase=keyword argument toname=to match__init__signature.fireworks/utilities/tests/test_filepad.py:ObjectIdfor proper GridFS existence checks.test_update_file: Add round-trip assertion — after update, verifyget_file()returns updated content andgfs_idmatches.test_update_file_by_id: Add round-trip assertion — after update, verifyget_file_by_id()returns correct content and metadata.This fix also contains docstring and package doc changes relevant to FilePad's file update functionality.