Regression in d2afa5eb2308e672b6313876856e32e2561b90f3. Backport of 5032556483f16b0b5f182e393eb5c6548fc505be from master