Skip to content

fix: refuse to silently overwrite existing files in save_data (#539) - #545

Open
Shashankss1205 wants to merge 1 commit into
mainfrom
fix/539-save-data-overwrite
Open

fix: refuse to silently overwrite existing files in save_data (#539)#545
Shashankss1205 wants to merge 1 commit into
mainfrom
fix/539-save-data-overwrite

Conversation

@Shashankss1205

Copy link
Copy Markdown
Collaborator

Fixes #539.

Problem

save_data silently overwrote an existing file with no indication — inconsistent with save_model, which refuses to write into a non-empty path.

Fix

  • New overwrite: bool = False parameter (plumbed through the MCP schema and dispatch). An existing target is refused with "File already exists: ''. Pass overwrite=true to replace it..."; with overwrite=true the write proceeds and the response reports overwritten: true. Fresh writes report overwritten: false.
  • Also expanduser() the path, so save_data(path="~/x") no longer creates a literal ~ directory in the server cwd — the same footgun fixed for save_model in fix: expand and resolve local paths in save_model/load_model #526.

Testing

  • New test_save_refuses_existing_file: first write succeeds, second to the same path is refused, third with overwrite=true succeeds and reports overwritten: true.
  • Updated the existing csv/json tests to fresh paths (they previously wrote into a pre-created NamedTemporaryFile, which the new guard correctly refuses) and assert overwritten: false.
  • Schema lint (test_schema_types) passes with the new typed overwrite property.
  • Full suite: 261 passed.

🤖 Generated with Claude Code

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>
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.

[BUG] save_data silently overwrites existing files

1 participant