Fix error for NameError: undefined local variable or method provider