cherrypick fix for #1360 into 1.5-branch