You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Model.var_by_name throws error if the model contains no variables when using gurobi as solver #422
The behavior of the function model.get_var_by_name() is unexpected when using Gurobi as solver. According to the docstring, the function should return None if no variable with that name exists. However, when using it with Gurobi, I get an error ParameterNotAvailable when using the function on a model without any variables.
To Reproduce
Create an instance of a model with Gurobi as solver
Use the model.var_by_name(name="randomname") function.
model = mip.Model(solver_name=mip.GUROBI)
variable = model.var_by_name(name="variablename")
Expected behavior
From the docstring, None should be returned.
Desktop (please complete the following information):
Operating System, version: WSL2 on Windows 11
Python version: 3.13.11
Python-MIP version (we recommend you to test with the latest version):
Additional context
The behavior of Gurobi is different than for example HiGHS here, which does not throw the error. In my opinion the behavior of Model.var_by_name() should not be solver dependent.
The exact same problem exists for the constraint version of this function, namely model.constrs_by_name()
changed the title [-]get_var_by_name throws error with non-existing name when using gurobi as solver[/-][+]get_var_by_name throws error if the model contains no variables when using gurobi as solver[/+]on Apr 23, 2026
changed the title [-]get_var_by_name throws error if the model contains no variables when using gurobi as solver[/-][+]Model.var_by_name throws error if the model contains no variables when using gurobi as solver[/+]on Apr 24, 2026
Activity
[-]get_var_by_name throws error with non-existing name when using gurobi as solver[/-][+]get_var_by_name throws error if the model contains no variables when using gurobi as solver[/+]linde-frolke commentedon Apr 23, 2026
I would like to solve the issue if you want me to :)
[-]get_var_by_name throws error if the model contains no variables when using gurobi as solver[/-][+]Model.var_by_name throws error if the model contains no variables when using gurobi as solver[/+]