TimefoldAI / timefold-solver-python

Timefold Solver is an AI constraint solver for Python to optimize the Vehicle Routing Problem, Employee Rostering, Maintenance Scheduling, Task Assignment, School Timetabling, Cloud Optimization, Conference Scheduling, Job Shop Scheduling, Bin Packing and many more planning problems.
https://timefold.ai
Apache License 2.0
26 stars 3 forks source link

Error message for error in constraint provider must mention the line #82

Open ge0ffrey opened 2 weeks ago

ge0ffrey commented 2 weeks ago

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.

Christopher-Chianelli commented 2 weeks ago

I think this is related to https://github.com/jpype-project/jpype/pull/1057

How a ConstraintProvider is constructed go through these steps:

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.