timefold-solver
timefold-solver copied to clipboard
Error message for error in constraint provider must mention the line
What line did this happen on?
Traceback (most recent call last):
File "/home/ge0ffrey/projects/tf/tf-main/timefold-quickstarts/python/employee-scheduling/.venv/bin/run-app", line 5, in <module>
from employee_scheduling import main
File "/home/ge0ffrey/projects/tf/tf-main/timefold-quickstarts/python/employee-scheduling/src/employee_scheduling/__init__.py", line 3, in <module>
from .routes import app
File "/home/ge0ffrey/projects/tf/tf-main/timefold-quickstarts/python/employee-scheduling/src/employee_scheduling/routes.py", line 23, in <module>
solver_manager = SolverManager.create(SolverFactory.create(solver_config))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ge0ffrey/projects/tf/tf-main/timefold-quickstarts/python/employee-scheduling/.venv/lib64/python3.11/site-packages/timefold/solver/_solver_factory.py", line 52, in create
delegate = JavaSolverFactory.create(solver_config) # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
NameError: name 'Availability' is not defined
I suspect line 75 in constraints.py:
def unavailable_employee(constraint_factory: ConstraintFactory):
return (constraint_factory.for_each(Shift)
.join(Availability,
The error message dosn't mention "line 75" nor the filename.
I think this is related to https://github.com/jpype-project/jpype/pull/1057
How a ConstraintProvider is constructed go through these steps:
- Python calls Java
SolverFactoryto create aSolver - Java
SolverFactorycreate an instance of the generatedConstraintProviderclass and call itsdefineConstraintsmethod -
defineConstraintscall into Python to compile the Python functions used in constraints and return to Java
The Python code in defineConstraints throws a name error since Availability is not in globals (missed import or removed class). This exception then goes to Java, which replaces its stack trace with its own.