Fix infinite recursion bug when `func` raises AttributeError.