Apply patch from #8944.
Fixes #8944.