Hi Rails Core team,
I’ve been developing TransactionGuard, a Ruby gem that detects external side effects performed inside Active Record transactions.
For example, sending an HTTP request, delivering an email, or enqueueing a background job inside a transaction can create inconsistencies if the database transaction later rolls back. The external operation cannot automatically be rolled back with the database changes.
TransactionGuard currently provides detection for HTTP requests, email delivery, and background job enqueueing, with configurable warning, raise, and off modes.
I’d appreciate feedback on whether this type of protection could be valuable as an optional Active Record development feature in Rails itself.
Some questions I’d like to discuss:
-
Should Rails provide built-in warnings for external side effects inside transactions?
-
Which operations should be covered, and how could detection avoid false positives?
-
Should this be an opt-in development/testing feature rather than enabled by default?
-
Would this functionality fit better in Active Record or remain a separate gem?
I understand that Rails already provides transaction callbacks, including after_commit, for handling work after a successful commit. My goal is to explore whether additional detection could help developers catch potentially unsafe patterns earlier.
I’d welcome feedback on the use case, design, and whether an upstream contribution would make sense.
Thank you!