Avoid method call if `@transaction_state` is not finalized
#36049

kamipo wants to merge kamipo:avoid_method_call into rails:master

We do not currently have an analysis of these two commits