Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

python: hello-world / JavaException when using DEBUG log level #103

Closed
Alex-K37 opened this issue Jun 30, 2024 · 2 comments · Fixed by #101
Closed

python: hello-world / JavaException when using DEBUG log level #103

Alex-K37 opened this issue Jun 30, 2024 · 2 comments · Fixed by #101
Labels
bug Something isn't working process/needs triage

Comments

@Alex-K37
Copy link

Alex-K37 commented Jun 30, 2024

Describe the bug

Turning on DEBUG logging causes exceptions with the hello-world example.

Expected behavior
More detailed log messages.

Actual behavior

The following error is shown (only first few lines):

Traceback (most recent call last):
File "DefaultSolver.java", line 200, in ai.timefold.solver.core.impl.solver.DefaultSolver.solve
Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/***/.virtualenvs/timefold/lib/python3.11/site-packages/timefold/solver/_solver.py", line 109, in solve
java_solution = self._delegate.solve(java_problem)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ai.timefold.jpyinterpreter.types.errors.ai.timefold.jpyinterpreter.types.errors.AttributeError: ai.timefold.jpyinterpreter.types.errors.AttributeError: object '08:30' does not have attribute 'strftime'

To Reproduce

diff --git a/python/hello-world/src/hello_world/main.py b/python/hello-world/src/hello_world/main.py
index 660f7430..4b60fade 100644
--- a/python/hello-world/src/hello_world/main.py
+++ b/python/hello-world/src/hello_world/main.py
@@ -10,7 +10,7 @@ from .domain import *
from .constraints import define_constraints

-logging.basicConfig(level=logging.INFO)
+logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger('app')

Environment

Timefold Solver Version or Git ref:
1.11.0b0

Output of java -version:
openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment (build 17.0.11+9-suse-150400.3.42.1-x8664)
OpenJDK 64-Bit Server VM (build 17.0.11+9-suse-150400.3.42.1-x8664, mixed mode, sharing)

Output of uname -a or ver:
Linux think14 5.14.21-150500.55.65-default TimefoldAI/timefold-solver#1 SMP PREEMPT_DYNAMIC Thu May 23 04:57:11 UTC 2024 (a46829d) x86_64 x86_64 x86_64 GNU/Linux

@triceo
Copy link
Contributor

triceo commented Jul 1, 2024

Thanks for reporting, @Alex-K37! We'll take a look when time permits.

@triceo triceo transferred this issue from TimefoldAI/timefold-solver Jul 1, 2024
@Christopher-Chianelli
Copy link
Collaborator

Caused by the issue this fixes: #101 ; The gist of it is because Python datetime classes are C-Native, we need to implement our own to avoid FFI calls (that is, Python calling Java or Java calling Python). The datetime classes were missing a few methods that deal with formatting. The hello-world and school-timetabling examples used said unimplemented method in their __str__ function. The __str__ function is only called when DEBUG logging or lower is used.

If you modified the __str__ function of Timeslot to not call strftime, no exception would occur.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working process/needs triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants