fix: skip invoice.upcoming webhook to prevent NOT NULL violation#103
Open
yoshifumi-kondo wants to merge 1 commit intostripe-experiments:mainfrom
Open
Conversation
…ipe-experiments#102) The invoice.upcoming event contains a preview invoice without an id field, causing a NOT NULL constraint violation on the invoices table. Remove it from the event handler registry and add a defensive guard in processEvent() to skip any event whose data.object lacks an id.
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.
Summary
invoice.upcomingfrom the event handler registry — this event contains a preview invoice without anidfield, which causes a NOT NULL constraint violation on theinvoicestable's generatedidcolumnprocessEvent()to skip any event whosedata.objectlacks anid, protecting against similar edge cases from future Stripe event typesinvoice.upcomingFixes #102
Context
Stripe sends
invoice.upcoming7 days before subscription renewal. Unlike regular invoices, this is a preview object with noid. The sync engine'sinvoicestable uses:When
_raw_datahas noidkey, this evaluates toNULL, violating the PRIMARY KEY constraint and returning HTTP 500 to Stripe.Changes
packages/sync-engine/src/stripeSync.tsinvoice.upcominghandler + add id-less event guardREADME.md/docs/index.mdinvoice.upcomingas handled (acknowledged & skipped)packages/sync-engine/src/stripeSync-invoice-upcoming.test.tspackages/fastify-app/src/test/stripe/invoice_upcoming.jsonpackages/fastify-app/src/test/webhooks.test.tsTest plan
pnpm vitest run stripeSync-invoice-upcoming.test.ts— 4/4 passing)invoice_upcoming.jsonfixtureinvoice.paid,invoice.created, etc.)