Events with same timestamps don't persist most recent event data

Open
#268 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
postgresql, typescript
Domain
database, payments

Research direction

Start at packages/sync-engine/src/database/postgres.ts around line 203 and inspect the timestamp comparison used when webhook events update subscriptions. Reproduce the trial-to-another-subscription sequence, verify that trial_will_end and updated can share a timestamp, and confirm the updated event's subscription is the value persisted in Postgres.

Written by the indexing model from the issue text.

Description

bug

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Switching from a subscription in trial to another subscription, results in the subscription in trial still persisting in the database as the active subscription after webhook events are handled.

To Reproduce

  1. Create a subscription to product with trial.
  2. While in trial update to another subscription.
  3. Note that the following webhook events trigger:
customer.subscription.trial_will_end
customer.subscription.updated
...
  1. The webhook handler updates the subscription from the trial_will_end event.
  2. The webhook ignores the subscription from updated event because it has the exact same timestamp as trial_will_end event

Expected behavior

Subscription from customer.subscription.updated event should be the last one to be persisted in database, not trial_will_end

Additional context

Changing this comparison to <= seems to resolve this issue:
https://github.com/supabase/stripe-sync-engine/blob/10955c71fdfb52be84c977ef8ca6b6841c6f0ba3/packages/sync-engine/src/database/postgres.ts#L203

Dominant language
TypeScript
Stars
1.1k
Forks
117
Avg merge
12m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stripe/sync-engine

All issues in stripe/sync-engine

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.