Apply patch from #8647.
Fixes #8647.