Regression in 4a246a02bdcbc13b15480c014f51cb0682af7c1e. Backport of 362fba87c9bb4f88542ba82ce4a732fed2634be7 from master