Backport PR #3992 to 1.7