fix: honor overwrite when flattening local resources - #2695
Open
林SO (Linxiushen) wants to merge 1 commit into
Open
林SO (Linxiushen) wants to merge 1 commit into
林SO (Linxiushen) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
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
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.
Describe your changes
Saving a local folder with
save_to_dir(output_dir, flatten=True)currently overwrites existing destination files even whenoverwriteis omitted or explicitly False. The collision check only runs foroverwrite=True, after whichcopytree(..., 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.pypasses, including Pylint, Ruff, and formatting;git diff --checkpasses.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
lintrunner -a(changed files).Release note: Flattened local resource saves now honor
overwrite=Falseand 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.