Repository navigation
fix(local): say the database copy failed when removing its partial file fails too - #2187
Conversation
…le fails too Beneath a file, macOS and Linux refuse the unlink in the error handler with NotADirectoryError, which replaced the snapshot error start is meant to give; Windows calls the file missing, so the handler passed there.
|
@ybai08 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughWhen snapshot creation fails, cleanup now suppresses ChangesSnapshot error handling
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to When a pre-upgrade snapshot fails, users now see the real snapshot error instead of a confusing cleanup error. The migration still does not run after a snapshot failure. The change is small and covered by an integration test, so merge risk is minimal. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
snapshot_before_upgradeno longer lets the cleanup in its error handler replace the error it is reporting. Removing the.partialfile is now wrapped incontextlib.suppress(OSError), so the caller always getsRuntimeError: could not write a database snapshot to ... before migrating: <reason>.Why
One of the three integration failures that #2186 uncovered once the unit step passed (the integration step had not run on a PR since 2026-10-05 18:47 UTC):
The test puts a file where the backups folder should be.
mkdirraisesFileExistsError, and the handler then callspartial.unlink(missing_ok=True)on a path beneath that file. macOS and Linux answer that withENOTDIR, whichmissing_okdoes not cover, so theNotADirectoryErrorescapes instead of theRuntimeError. Windows reports the path as not found, whichmissing_okswallows, so the test passes there.The upgrade is still not run in either case, so no database migrates without a copy. What is lost on macOS and Linux is the message: start fails with a bare
NotADirectoryErroron the.partialpath rather than the sentence that says the copy could not be written and why.How to test
cd surfsense_local/backend && uv run pytest -m integration tests/integration/test_migration_snapshot.pyghcr.io/astral-sh/uv:python3.12-bookworm-slim, arm64): 5 passed.devfails the existing test there with the runner's message.test_a_cleanup_that_fails_too_still_reports_the_copymakes the removal of the partial file raise through a patchedPath.unlink, so the handler is exercised on Windows as well, where the existing test cannot reach it. It fails without the fix.ruff checkandruff format --checkon both files.Not run: Windows. The new test's claim about Windows (that
mkdiron an existing file raisesFileExistsErrorthere) is from the standard library's code, not from a run.This PR's
Backendjob will still be red until #2186 and the other two integration failures are fixed; the snapshot test should be gone from its list.High-level PR Summary
This PR fixes an error handling issue in the database migration snapshot logic where cleanup failures during error recovery could mask the original error. Specifically, when the system attempts to create a backup before upgrading the database but that backup fails (e.g., when the backup directory is blocked by a file), removing the partial backup file could also fail on macOS and Linux, causing a
NotADirectoryErrorto replace the more informativeRuntimeErrorabout the snapshot failure. The fix wraps the cleanup operation incontextlib.suppress(OSError)to ensure the original error message always reaches the user.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_local/backend/shared/migration_snapshot.pysurfsense_local/backend/tests/integration/test_migration_snapshot.pySummary by CodeRabbit