Skip to content

Commit

Permalink
Handle SystemError in JDBCBackend.get()
Browse files Browse the repository at this point in the history
Occurs only with Python 3.12 and JPype 1.5.0.
  • Loading branch information
khaeru committed Jan 8, 2024
1 parent b7eb952 commit 6ab08fc
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ixmp/backend/jdbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"at.ac.iiasa.ixmp.objects.Scenario",
"at.ac.iiasa.ixmp.Platform",
"java.lang.Double",
"java.lang.Exception",
"java.lang.Integer",
"java.lang.NoClassDefFoundError",
"java.lang.IllegalArgumentException",
Expand Down Expand Up @@ -147,7 +146,7 @@ def _handle_jexception():
"""Context manager form of :func:`_raise_jexception`."""
try:
yield
except java.Exception as e:
except jpype.JException as e:
_raise_jexception(e)


Expand Down Expand Up @@ -708,10 +707,18 @@ def get(self, ts):
# either getTimeSeries or getScenario
method = getattr(self.jobj, "get" + ts.__class__.__name__)

# Re-raise as a ValueError for bad model or scenario name, or other
with _handle_jexception():
# Re-raise as a ValueError for bad model or scenario name, or other with
# with _handle_jexception():
try:
# Either the 2- or 3- argument form, depending on args
jobj = method(*args)
except SystemError:
# JPype 1.5.0 with Python 3.12: "<built-in method __subclasscheck__ of
# _jpype._JClass object at …> returned a result with an exception set"
# At least transmute to a ValueError
raise ValueError("model, scenario, or version not found")
except BaseException as e:
_raise_jexception(e)

self._index_and_set_attrs(jobj, ts)

Expand All @@ -728,7 +735,7 @@ def check_out(self, ts, timeseries_only):
def commit(self, ts, comment):
try:
self.jindex[ts].commit(comment)
except java.Exception as e:
except jpype.JException as e:
arg = e.args[0]
if isinstance(arg, str) and "this Scenario is not checked out" in arg:
raise RuntimeError(arg)
Expand Down

0 comments on commit 6ab08fc

Please sign in to comment.