Regression in aadd3aeb2ba3153e35bd805c80c901f289a6f333. Backport of 0a37ea56d05208e31ed2f29fdffca65b6d92fa2e from master