{
  "id": 21409324,
  "title": "4 bugs readers found in my Postgres booking trigger (and how I fixed them)",
  "url": "https://urgent.news/2026/11/23/4-bugs-readers-found-in-my-postgres-booking-trigger-and-how-i-fixed",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-23T14:44:45.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/yassine_khattari_3cb9d27d/4-bugs-readers-found-in-my-postgres-booking-trigger-and-how-i-fixed-them-2ahf"
  },
  "original_language": "en",
  "account": "This article describes four bugs found in the author's Postgres booking trigger for preventing double bookings, along with the fixes for each issue. The first bug is that the trigger runs with the wrong privileges, causing it to miss other users' bookings when Row Level Security is enabled. The fix is to run the function as its owner and set a fixed search_path. The second bug is that the trigger only fires on INSERT, not on UPDATE. This oversight allows a client to book a slot that becomes unavailable after the payment is confirmed, by updating the booking status to \"confirmed\". The solution is to fire the trigger on UPDATE as well, excluding the row itself from the overlap query. The third bug is that the webhook handler does not check for errors when updating the booking with Stripe's library, resulting in silent failures and charged but unconfirmed bookings. The fix is to check the response for errors and handle them appropriately, refunding or retrying as needed. The fourth bug is that an UPDATE statement that matches zero rows is treated as a success, causing similar issues to the previous one. The author resolves this by asking for the updated rows back and treating each outcome differently, such as refunding or retrying based on the specific case. The article concludes by emphasizing the importance of testing, error handling, and public code review to catch and address such bugs.",
  "summary": "A few weeks ago I wrote about preventing double bookings in Postgres with advisory locks, and recorded a short video where I test it live with two concurrent requests: Readers reviewed the code, and reviewing it myself again turned up more. This post lists four real problems, what each one looked like, and the fix. If you build booking or checkout flows, you may have the same bugs. Bug 1: the…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}