rails icon indicating copy to clipboard operation
rails copied to clipboard

prepend option is no longer supported for after_commit callbacks in Rails 7.1 defaults

Open jrochkind opened this issue 5 months ago • 2 comments

As a result of #46992 (@tenderlove), with new Rails 7.1 default run_after_transaction_callbacks_in_order_defined true, prepend option is no longer supported for any transactional callbacks. (after_commit)

We can see how in the presence of this configugration prepend:true is hardcoded, and then passed to set_options_for_callbacks! method such that it will over-ride any prepend arg otherwise passed in, for all after_commit and after_rollback "transactional" callbacks.

https://github.com/rails/rails/pull/46992/files#diff-8dd03b7fb9b72a3bd338955c1de75652d60453230c6544f3851c0d0b3746a675R270-R275

The effect of this is that prior to run_after_transaction_callbacks_in_order_defined, you could use prepend:true to alter callback order when definining new transactional callbacks.

But after #46992, not only is the default order reversed, but you can no longer use prepend:true to alter the order.

This is not mentioned in the #46992 or any related docs/changenotes. prepend: true is still mentioned as an option for before_destroy in guide as well as header docs on ActiveRecord::Callbacks

prepend:true is mentioned in passing in the docs for run_after_transaction_callbacks_in_order_defined, but I guess it's not clear if it's meant to apply to after_commit there?

  1. If it is intended that prepend option is removed from after_commit and transactional callbacks when run_after_transaction_callbacks_in_order_defined is set, i guess the docs should mention this?

  2. If it is a bug that prepend:true no longer works for after_commit callbacks in Rail 7.1 with default config, then we could fix it in a PR?

jrochkind avatar Nov 20 '23 18:11 jrochkind