Skip to content

fix: honor overwrite when flattening local resources - #2695

Open
林SO (Linxiushen) wants to merge 1 commit into
microsoft:mainfrom
Linxiushen:fix/flattened-resource-overwrite
Open

林SO (Linxiushen) wants to merge 1 commit into
microsoft:mainfrom
Linxiushen:fix/flattened-resource-overwrite

Conversation

@Linxiushen

Copy link
Copy Markdown

Describe your changes

Saving a local folder with save_to_dir(output_dir, flatten=True) currently overwrites existing destination files even when overwrite is omitted or explicitly False. The collision check only runs for overwrite=True, after which copytree(..., dirs_exist_ok=True) replaces the files. This path is also used when exporting ONNX models with external data or additional files.

Check flattened destination entries with the existing overwrite guard before copying when overwrite is disabled. A conflict now raises FileExistsError, matching ordinary resource saves. Explicit overwrite retains its existing replacement behavior.

Add regression coverage for file and directory conflicts, default and explicit False flags, explicit overwrite, nonconflicting saves, and preservation of unrelated destination files.

Validation: the focused resource-path suite changed from 4 failures / 10 passes on unchanged production code to 14 passes after the fix, using real filesystem operations. lintrunner -a olive/resource_path.py test/resource_path/test_resource_path.py passes, including Pylint, Ruff, and formatting; git diff --check passes.

Local test scope: Python 3.12, with an external runner that bypasses the unrelated Olive CLI initializer and repository-wide model fixtures, and uses ordinary temporary directories to avoid this Windows host's pytest symlink stall. The committed tests use standard imports/fixtures and do not mock copying or resource handling. Normal import and CLI smoke checks were attempted after installing the lightweight startup dependencies; both reach the model configuration import and require PyTorch, which is absent from the focused environment. Full model/integration tests were not run.

Prepared with AI assistance; validation scope and limitations are stated above.

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass. Focused suite passes; full suite was not run.
  • Update documents if necessary. No API change or new option.
  • Lint and apply fixes to your code by running lintrunner -a (changed files).
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.

Release note: Flattened local resource saves now honor overwrite=False and reject conflicting destination entries before copying, preventing existing model files from being silently replaced.

(Optional) Issue link

Discovered and reproduced from the current resource export path; reproduction and regression coverage are included in this PR.

Copilot AI lite review requested due to automatic review settings September 27, 2026 18:41
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Fixes flattened local resource saves so overwrite=False rejects destination conflicts before copying.

Changes:

  • Added conflict checks for flattened directory entries.
  • Added regression tests for conflicts, overwrites, and unrelated files.
File Description
test/​resource_path/​test_resource_path.py Covers flattened-save conflict and overwrite behavior.
olive/​resource_path.py Enforces overwrite protection during flattening.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants