A tiny detail that completely changes how your debugger behaves

Yesterday, while trying to create example errors on my localhost for another article, I accidentally found a real bug during my normal workflow.

While debugging it, I noticed something worth sharing 👇

When you put a debugger outside the ActiveRecord::Base.transaction block, it doesn’t follow the same data flow as when you put it inside — which makes total sense when you think about it.

Imagine you have a method that updates a record with critical information — a few dependent steps like:

application.update(reference: SHA)
user.update(processed_application: application)
application.update(state: 'processed')

All these steps need to succeed.
If one fails, you want to roll back the rest — that’s what the ActiveRecord::Base.transaction is for.

So when you place your debugger outside the block, it won’t step through properly if something fails.
The right way to debug it is to put the debugger inside the transaction block.

That way, you can follow each step separately and see exactly where things break.

🐛 Small detail — big difference when tracking what’s really happening in your code.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.