Fix #29472. Regression of #29236, a "if" check was missing. (cherry picked from commit 10cfa0879a538a470598281d7093de3555c018be)