KamoCRM

Deleting a mortgage application no longer 500s, and a received one is kept (SITP TP21FU)

Fixkamo-shared-library
Shipped
October 18, 2026 at 11:01 PM UTC
Author
Kamo
Commit
4b69c3e

DELETE **************** failed for every application: AppMortgageService.delete removed the borrowers through the JPA cascade while borrower_declarations / borrower_hmda (and the seven other borrower satellites, which Borrower does not map) still pointed at them, and loan_conditions / milestones still pointed at the loan file. MortgageApplicationPurge now deletes the whole application in one transaction, children before parents, every statement bounded by the application's own keys through an index (sub-selects as = ANY (ARRAY(...)) so the planner never full-scans the unanalyzed tables). The order is pinned against the production foreign keys. Retention decision (MLOS doc 07 s9.2, doc 12; Reg B 1002.12, HMDA, TRID): only an application that was never received may be physically deleted - a DRAFT, or withdrawn straight from DRAFT, with no application date and no record of business (disclosures, TRID/Reg X/adverse-action timers, locks, AUS, vendor/credit orders, consent, communications, notices, findings, commitments, MERS, closing, sign-off, registered identifiers). Anything else throws ApplicationRetainedException before anything changes (callers answer 409: withdraw it instead). The append-only audit spine, training labels, pricing runs and vault documents are never deleted.

All changes

Like what you see shipping?

All of it arrives in your workspace on its own. Start on the free plan and read this page again in a month.

Start Free ForeverView Pricing