Files
sure/test/models/lunchflow_item
Lobster 8b4bb64a23 fix(lunchflow): prune orphaned accounts deleted upstream (#1861) (#1886)
* fix(lunchflow): prune orphaned accounts deleted upstream (#1861)

Accounts deleted in Lunch Flow lingered in Sure as unlinked
LunchflowAccount records, permanently pinning the item to "Need setup".
The importer created/updated accounts returned by the API but never
removed records for accounts that disappeared upstream.

Add prune_orphaned_lunchflow_accounts, mirroring SimpleFin's
prune_orphaned_simplefin_accounts: after importing, delete LunchflowAccount
records whose account_id is no longer returned upstream and that are not
linked to an Account via AccountProvider. Linked accounts are kept so the
prune never cascade-destroys a user's Account. The prune is guarded to a
non-empty upstream list so a transient empty/failed response can't wipe out
all accounts.

Fixes #1861

* fix(lunchflow): prune NULL-id orphans + consistent import return shape (#1886)

* fix(lunchflow): make orphan prune resilient to destroy failures

Wrap the per-record destroy in begin/rescue so a single failed prune
doesn't abort the whole import. Pruning runs before transaction fetch,
so an unhandled error would have blocked transaction syncing entirely.
Matches the importer's existing continue-on-error convention.

* fix(lunchflow): only count pruned accounts when destroy succeeds

destroy returns false (without raising) when a before_destroy callback
halts deletion; the prior code incremented the pruned count regardless,
which could inflate it. Increment only on success and log when halted.
2026-07-17 22:49:31 +02:00
..