Regression in f48bc7c3dbd204eefb3c19016b1e4906ac26bee3. Backport of 81e357a7e19f35235cc998459a10213532727d4e from master