Your code is not valid, so I’m not sure what you’re trying to do. Please make a reproducible example:
In your function x <= 2 refers to the x binding created by model2. if you want x from model1, call the inner x something different so the binding doesn’t get over-written, or use model1[:x].