Fix regression on after_commit in nested transactions. (master)

related to #16432 .

[fixes #16425]

This is practically a backport of that fix, plus 1 commit to make it work.

This is to ensure the same behaviour as 3.2