Skip to content

fix: skip invoice.upcoming webhook to prevent NOT NULL violation#103

Open
yoshifumi-kondo wants to merge 1 commit intostripe-experiments:mainfrom
yoshifumi-kondo:bugfix-issue-102-skip-invoice-upcoming
Open

fix: skip invoice.upcoming webhook to prevent NOT NULL violation#103
yoshifumi-kondo wants to merge 1 commit intostripe-experiments:mainfrom
yoshifumi-kondo:bugfix-issue-102-skip-invoice-upcoming

Conversation

@yoshifumi-kondo
Copy link

Summary

  • Remove invoice.upcoming from the event handler registry — this event contains a preview invoice without an id field, which causes a NOT NULL constraint violation on the invoices table's generated id column
  • Add a defensive guard in processEvent() to skip any event whose data.object lacks an id, protecting against similar edge cases from future Stripe event types
  • Add unit tests verifying the fix and a test fixture for invoice.upcoming

Fixes #102

Context

Stripe sends invoice.upcoming 7 days before subscription renewal. Unlike regular invoices, this is a preview object with no id. The sync engine's invoices table uses:

id TEXT GENERATED ALWAYS AS ((_raw_data->>'id')::TEXT) STORED NOT NULL

When _raw_data has no id key, this evaluates to NULL, violating the PRIMARY KEY constraint and returning HTTP 500 to Stripe.

Changes

File Change
packages/sync-engine/src/stripeSync.ts Remove invoice.upcoming handler + add id-less event guard
README.md / docs/index.md Mark invoice.upcoming as handled (acknowledged & skipped)
packages/sync-engine/src/stripeSync-invoice-upcoming.test.ts 4 unit tests
packages/fastify-app/src/test/stripe/invoice_upcoming.json Test fixture
packages/fastify-app/src/test/webhooks.test.ts Add fixture to test suite

Test plan

  • Unit tests pass (pnpm vitest run stripeSync-invoice-upcoming.test.ts — 4/4 passing)
  • Fastify webhook integration test passes with invoice_upcoming.json fixture
  • Verify no regression on existing invoice event handling (invoice.paid, invoice.created, etc.)

…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.
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.

invoice.upcoming webhook causes NOT NULL violation on id column

1 participant

Comments