fix: prevent data corruption in invoice share links and contract legacy fallback#9
Draft
cursor[bot] wants to merge 3 commits intomainfrom
Draft
fix: prevent data corruption in invoice share links and contract legacy fallback#9cursor[bot] wants to merge 3 commits intomainfrom
cursor[bot] wants to merge 3 commits intomainfrom
Conversation
generateInvoiceShareLink unconditionally set status to 'unpaid', silently reverting paid invoices back to unpaid when a user copies a share link. This corrupts income tracking data. Now reads current status first and only transitions draft/archived invoices to 'unpaid'; paid and already-unpaid invoices are left untouched. Co-authored-by: Ananta Mishra <anantamishra@users.noreply.github.com>
isLegacyContractConstraintOrSchemaError had a missing parentheses group, causing any error containing the word 'status' to trigger the legacy fallback path. This silently dropped deliverables, milestones, clauses, and other extended columns during contract create/update operations. Removed the overly broad 'status' branch and added proper grouping for the column-missing check. Co-authored-by: Ananta Mishra <anantamishra@users.noreply.github.com>
Covers the operator-precedence fix to prevent regression. Verifies that generic errors containing 'status' no longer falsely trigger the legacy fallback path. Co-authored-by: Ananta Mishra <anantamishra@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
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.
Critical bugs found and fixed
Bug 1: Invoice share links silently revert paid invoices to unpaid
Impact: Data corruption — income tracking becomes inaccurate, paid invoices appear unpaid.
Root cause:
generateInvoiceShareLinkinlib/api/invoices.tsunconditionally executed.update({ status: 'unpaid' })on every call. When a user copies a share link for a paid invoice, its status is silently reset tounpaid, corrupting the income tracker.Trigger scenario: User marks invoice as paid → clicks "Copy share link" to send the payment confirmation URL to a client → invoice status reverts to unpaid → income tracker shows lower revenue.
Fix: Read the current status before updating. Only transition
draft/archivedinvoices tounpaid;paidand already-unpaidinvoices are left untouched. The share token generation still works in all cases.Bug 2: Operator precedence causes silent data loss on contract save
Impact: Silent data truncation — deliverables, milestones, clauses, and other extended columns are silently dropped.
Root cause:
isLegacyContractConstraintOrSchemaErrorinlib/api/contracts.tshad a missing parentheses group:Any error message containing the word "status" (e.g.
"Failed to update contract status","Request failed with status code 500") would falsely trigger the legacy fallback path, which silently drops deliverables, milestones, clauses, and all extended schema columns.Trigger scenario: A transient network error or any Supabase error containing "status" during contract create/update → code enters legacy fallback → contract is saved with missing deliverables, milestones, and clauses.
Fix: Removed the overly broad
lower.includes('status')branch and added proper parentheses grouping.Validation