After_commit callbacks unexpectedly run in the REVERSE order they are declared, unlike all other callbacks

IMHO there’s no room for discussion on this one. It’s a bug that is very annoying.

Your after_commit callbacks will run in the REVERSE order they are declared on the model, unlike all other callbacks that, as expected, will run in the exact order they are declared in the model.

There’s an issue about this on GitHub but it’s closed, even tough it’s still very active (most recent post 5 days ago): after_commit order inconsistent with other callbacks · Issue #20911 · rails/rails · GitHub

1 Like

Thanks for bringing this up!

To me, it looks like what happened is that a PR addressing the issue you cite got merged. I don’t know whether it was an incomplete fix or whether there was a regression, but either way, that bug looks like it was closed in good faith. So new activity on the bug isn’t likely to bring it to the maintainers’ attention.

If you feel able, I’d suggest opening a fresh bug referencing the old one. That seems like it might make it clearer that this is still an unsolved problem.

1 Like

This bothers me, too, and I’d like to address it.

There was a PR to address the issue, which was superseded by another PR, which fizzled out. I’ll reopen the original issue.