`keys_to_invalidate` is undefined and causes a `NameError: undefined local variable or method `keys_to_invalidate'`.