Fix UnboundLocalError regression due to previous incorrect fix for
issue 16248.