Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pyiron_workflow/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,16 @@ def _save(
if self._fallback(cloudpickle_fallback):
attacks += [(self._CLOUDPICKLE, cloudpickle.dump)]

e = None
e: Exception | None = None
for suffix, save_method in attacks:
e = None
p = filename.with_suffix(suffix)
try:
with open(p, "wb") as filehandle:
save_method(node, filehandle)
return
except Exception:
except Exception as ee:
e = ee
p.unlink(missing_ok=True)
if e is not None:
raise e
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from pathlib import Path
from tempfile import TemporaryDirectory

import cloudpickle
from pint import UnitRegistry

from pyiron_workflow.nodes.function import as_function_node
from pyiron_workflow.nodes.standard import UserInput
from pyiron_workflow.storage import PickleStorage, TypeNotFoundError, available_backends
Expand Down Expand Up @@ -134,6 +137,21 @@ def Unimportable(x):
finally:
interface.delete(node=u, cloudpickle_fallback=True)

def test_uncloudpickleable(self):
ureg = UnitRegistry()
with self.assertRaises(
TypeError,
msg="Sanity check that this can't even be cloudpickled"
):
cloudpickle.dumps(ureg)

interface = PickleStorage(cloudpickle_fallback=True)
n = UserInput(ureg, label="uncloudpicklable_node")
with self.assertRaises(
TypeError,
msg="Exception should be caught and saving should fail"
):
interface.save(n)

if __name__ == "__main__":
unittest.main()
Loading