Repro and debugging for #5738 in rails/rails