Backport fix for #974