Same fix as #832 but for 1.6 branch