Skip to content

Commit 0c1fde1

Browse files
pitrouogrisel
authored andcommitted
Fix #129: do not silence RuntimeError in dump() (#140)
1 parent abeb3fb commit 0c1fde1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cloudpickle/cloudpickle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ def dump(self, obj):
270270
if 'recursion' in e.args[0]:
271271
msg = """Could not pickle object as excessively deep recursion required."""
272272
raise pickle.PicklingError(msg)
273+
else:
274+
raise
273275

274276
def save_memoryview(self, obj):
275277
self.save(obj.tobytes())

tests/cloudpickle_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
from .testutils import assert_run_python_script
4848

4949

50+
class RaiserOnPickle(object):
51+
52+
def __init__(self, exc):
53+
self.exc = exc
54+
55+
def __reduce__(self):
56+
raise self.exc
57+
58+
5059
def pickle_depickle(obj, protocol=cloudpickle.DEFAULT_PROTOCOL):
5160
"""Helper function to test whether object pickled with cloudpickle can be
5261
depickled with pickle
@@ -862,6 +871,12 @@ def test_function_pickle_compat_0_4_1(self):
862871
b'\x14NtR.')
863872
self.assertEquals(42, cloudpickle.loads(pickled)(42))
864873

874+
def test_pickle_reraise(self):
875+
for exc_type in [Exception, ValueError, TypeError, RuntimeError]:
876+
obj = RaiserOnPickle(exc_type("foo"))
877+
with pytest.raises((exc_type, pickle.PicklingError)):
878+
cloudpickle.dumps(obj)
879+
865880

866881
class Protocol2CloudPickleTest(CloudPickleTest):
867882

0 commit comments

Comments
 (0)