Skip to content

A failed Lightroom import takes back the photos it added - #4087

Open
THEtheChad wants to merge 1 commit into
storytold:mainfrom
THEtheChad:fix/lr-import-atomic
Open

THEtheChad wants to merge 1 commit into
storytold:mainfrom
THEtheChad:fix/lr-import-atomic

Conversation

@THEtheChad

@THEtheChad THEtheChad commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4086

Problem

A Lightroom catalog import can fail after its file step has already added the catalog's originals and promoted Local photos into the library. The person sees only the error. The records stay, saved to disk, without the catalog's ratings, edits, keywords or collections. A real catalog reaches this through a photo Lightroom dates by its year alone (#3501: not a date: 2004).

Change

  • crates/engine/src/lightroom_job.rs, commit_prepared: when apply_prepared fails, take back the file step, then return the import's error. If the take-back also fails, the error says so, and its kind becomes Other.
  • crates/engine/src/lib.rs: Session::before_step, committed_step and take_back. take_back undoes exactly the one step committed since the checkpoint. It refuses if anything was committed, undone, redone or merged since then. If the step hasn't reached the library's log yet, it is dropped from the queue. If it has, its reversal is logged like an undo.
  • docs/lightroom-catalog-import.md: a failed import adds no photos.

The step is taken back rather than checked in advance: the checks need the file step's result, and the catalog batch's commit can't be checked without applying it.

Tests

  • a_failed_import_takes_back_the_originals_it_added and a_failed_import_leaves_the_photos_that_were_there_as_they_were (lightroom_catalog/tests.rs) run through Session::execute on a library on disk and check it again after reopening.
  • a_take_back_refuses_once_its_step_is_no_longer_the_last, a_take_back_drops_an_unwritten_step_and_logs_the_reversal_of_a_written_one and a_step_that_cannot_be_taken_back_stays_on_the_undo_stack (lightroom_job.rs).

Each fails with its part of the fix reverted: a plain return Err(e) fails 2, the missing queue drop 3, logging the reversal after the step 2, and the guard removed 1. cargo xtask ci passed all 9 steps on this branch (on main c2e9c45). With lightcraft-cli on a catalog with a year-only date, main leaves 2 records and this branch 0. The desktop window was not run.

Notes

…dded

`lightroom_job::commit_prepared` commits the import's file step (records
for the catalog's on-disk originals, and Local photos made the library's),
then applies the catalog. When that failed (a capture time Lightroom keeps
as a year or a month alone, collections it can't match safely, an album id
it can't give), the error returned with the file step still committed: the
originals stayed as records without the catalog's ratings, flags, edits or
collections, and were saved to disk.

The file step is now taken back when applying the catalog fails, as an
undo would, without leaving a redo step. `Session::committed_step` records
the one step committed since `Session::before_step`, and
`Session::take_back` reverses only that step, refusing when anything was
committed, undone or merged since. A step not yet written to the library's
log leaves the queue, so neither it nor its reversal reaches the disk.
When the take-back succeeds, the error is the one the import gave; when it
fails, the error says so as well.
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

When Lightroom catalog application fails after the file step commits, the import now attempts to take back that step. Session tracks whether a committed step can be safely reversed. Regression tests cover failed imports and take-back behavior.

Changes: Lightroom import rollback

Layer / File(s) Summary
Track and take back committed steps
crates/engine/src/lib.rs, crates/engine/src/lightroom_job.rs
Session records commit and undo state to identify a committed step. Take-back rejects steps whose state has changed, restores a step if reversal fails, and updates the pending log based on whether the forward operation was queued. Tests cover these cases.
Roll back failed catalog application
crates/engine/src/lightroom_job.rs, crates/engine/src/lightroom_catalog/tests.rs, docs/lightroom-catalog-import.md
commit_prepared attempts to take back its file step when catalog application fails. Tests check that failed imports restore library state, and the documentation describes the failure behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: bogusyogi, aiongg

Merge Risk: Minimal · up to c728c

A Lightroom import that fails while applying catalog data now takes back the photos it added. Tests cover the main failure cases. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed #4086 requires a failed Lightroom catalog application not to leave imported originals as bare library records or keep Local photos promoted. The PR records the file step and takes it back when `apply_…
Out of Scope Changes check Passed The changes to Session, the log queue, undo handling, tests, and import documentation support safe rollback of the failed import step. The PR description reports no unrelated dependencies, build cha…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main behavior change: when a Lightroom import fails partway, the photos it added are taken back. The raw summary describes commit_prepared attempting to take back the committed fi…
Full details: Linked Issues check

Explanation

#4086 requires a failed Lightroom catalog application not to leave imported originals as bare library records or keep Local photos promoted. The PR records the file step and takes it back when apply_prepared fails. The reported tests cover collection identity and invalid-date failures, check photos and Local status, and reopen the library to verify persistence. The PR does not address the catalog failure triggers, which is not required by #4086. Redo history and undo history evicted at the cap are explicitly outside the issue’s requested record-state behavior.

Full details: Out of Scope Changes check

Explanation

The changes to Session, the log queue, undo handling, tests, and import documentation support safe rollback of the failed import step. The PR description reports no unrelated dependencies, build changes, or other out-of-scope work. The documented exclusions concern behavior beyond the failed catalog-application case or history restoration, not unrelated changes.

Full details: Title check

Explanation

The title states the main behavior change: when a Lightroom import fails partway, the photos it added are taken back. The raw summary describes commit_prepared attempting to take back the committed file step when catalog application fails, and the linked objectives describe the same fix for issue #4086. The title is specific and matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c2e9c45 and c728cd5.

Files selected for processing: 4

  • crates/engine/src/lib.rs
  • crates/engine/src/lightroom_catalog/tests.rs
  • crates/engine/src/lightroom_job.rs
  • docs/lightroom-catalog-import.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

1234destiny1234 referenced this pull request in 1234destiny1234/lightcraft-classic Nov 15, 2026
… photos it added

When the catalog step of a Lightroom import fails after the file step has added the
catalog's originals, that step is taken back (Session::before_step / committed_step /
take_back), and the original error is returned (combined if the take-back also fails).
Ported by hand; the end-to-end failing-import tests are not ported (see PR notes).

Adapted from upstream #4087 (head c728cd5580c7f4a1adfb51d25ee9f4aedbea75e2)

Co-authored-by: THEtheChad <THEtheChad@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@THEtheChad
THEtheChad marked this pull request as draft November 17, 2026 18:29
@THEtheChad THEtheChad changed the title Issue #4086: a Lightroom import that fails part way takes back the photos it added A failed Lightroom import takes back the photos it added Nov 17, 2026
@THEtheChad
THEtheChad marked this pull request as ready for review November 17, 2026 19:50

@vangel76 vangel76 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed c728cd55. I checked the failed-import rollback, including its effect on pre-existing undo and redo history. I found one history loss.

Source review only. I did not build the project, run tests, or check CI.

Comment thread crates/engine/src/lib.rs
if self.commits != step.commits || self.undo.len() != step.undo_len {
return Err(EngineError::Other("the step to take back is no longer the last one".into()));
}
let mut e = self.undo.pop().ok_or_else(|| EngineError::Other("nothing to take back".into()))?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2. Preserve the existing history when an import rolls back. The temporary file step commits first, which clears existing redo entries and can evict the oldest undo entry at the limit. Taking back the new catalog step does not restore them. Undo an edit and then attempt an import that fails during Lightroom metadata: the unrelated Redo is gone. Delay those history changes until success, or restore the pre-existing entries during rollback. Extend the failed-import fixture with an unrelated redo action.

@wanikhawar wanikhawar mentioned this pull request Dec 1, 2026
3 of 32 tasks

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

I checked the take-back against main. It is correct, and I'd take it for v0.22.1 (#4964):

  • import::commit_prepared commits exactly one undo step, so committed_step finds it. When the import adds nothing, it returns None and nothing is taken back.
  • Every error in apply_prepared comes before its own s.commit, so the file step is still on top of the undo stack when take_back runs.
  • Nothing is saved to disk mid-command, because persist runs only at depth 0. So the queued op is normally still unwritten, and dropping it, rather than logging its reversal, is the right call.

Two notes, neither blocking:

  1. The redo history is still cleared by a failed import, as the earlier review found. The PR's Notes say so. Restoring it would mean holding back the file step's commit, so I'd leave that for a follow-up.
  2. When the reversal itself fails part way (CatalogError::PartlyApplied), take_back pushes the whole entry back onto the undo stack. undo_step instead keeps only what is left (rest_of_partial_step). This is an edge case, but the two paths could share that handling.

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.

A Lightroom import that fails part way keeps the photos it already added, without the catalog's data

3 participants