fix: refuse to silently overwrite existing files in save_data (#539) - #545
Open
Shashankss1205 wants to merge 1 commit into
Open
fix: refuse to silently overwrite existing files in save_data (#539)#545Shashankss1205 wants to merge 1 commit into
Shashankss1205 wants to merge 1 commit into
Conversation
save_data replaced an existing file with no indication, inconsistent with save_model (which refuses a non-empty path). Add an overwrite flag (default false): an existing target is refused with a clear message unless overwrite=true, and the response reports overwritten: true when a file was replaced. Also expanduser the path so "~/x" no longer creates a literal "~" directory (same footgun fixed for save_model in #526). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #539.
Problem
save_datasilently overwrote an existing file with no indication — inconsistent withsave_model, which refuses to write into a non-empty path.Fix
overwrite: bool = Falseparameter (plumbed through the MCP schema and dispatch). An existing target is refused with "File already exists: ''. Pass overwrite=true to replace it..."; withoverwrite=truethe write proceeds and the response reportsoverwritten: true. Fresh writes reportoverwritten: false.expanduser()the path, sosave_data(path="~/x")no longer creates a literal~directory in the server cwd — the same footgun fixed forsave_modelin fix: expand and resolve local paths in save_model/load_model #526.Testing
test_save_refuses_existing_file: first write succeeds, second to the same path is refused, third withoverwrite=truesucceeds and reportsoverwritten: true.NamedTemporaryFile, which the new guard correctly refuses) and assertoverwritten: false.test_schema_types) passes with the new typedoverwriteproperty.🤖 Generated with Claude Code