prefer `has_attribute?` over `attributes.key?`.

Follow up to the discussion on #16505.