Regression in 1b1f64ee5a78cc217fead52cbae23114502cf564. Backport of 04042b2b440f0bf50eb908d52cfe76af430e1738 from master