Fixes #12623. (cherry picked from commit 9de8a425) (cherry picked from commit 6f436404)
mentioned in commit a13aeadd