-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests for showing unpickling error * Add fix so exceptions can be loaded from pickle This fixes an issue where the PapermillExecutionError can be pickled but will not be unpicklable. Pythons BaseException class has a handling to make sure that exceptions are able to be loaded once they are pickled. This works by ensuring the args used to generate the instance are saved on the exception. However by only passing the message to the superclass, the pickle module was unable to load a new instance of PapermillExecutionError from a file. A new __str__ method was added to preserve the functionality of calling str() on the exception and only getting the error message back, while ensuring the superclass had access to all instantiating arguments. Co-authored-by: Tyler Calder <calder-ty@protonmail.com> Co-authored-by: Matthew Seal <mseal007@gmail.com>
- Loading branch information
1 parent
3f6225e
commit a318730
Showing
2 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,43 @@ | ||
import pickle | ||
import tempfile | ||
|
||
import pytest # noqa | ||
|
||
from .. import exceptions | ||
|
||
|
||
@pytest.fixture | ||
def temp_file(): | ||
f = tempfile.NamedTemporaryFile() | ||
yield f | ||
f.close() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"exc,args", | ||
[ | ||
( | ||
exceptions.PapermillExecutionError, | ||
(1, 2, "TestSource", "Exception", Exception(), ["Traceback", "Message"]), | ||
), | ||
(exceptions.PapermillMissingParameterException, ("PapermillMissingParameterException",)), | ||
(exceptions.AwsError, ("AwsError",)), | ||
(exceptions.FileExistsError, ("FileExistsError",)), | ||
(exceptions.PapermillException, ("PapermillException",)), | ||
(exceptions.PapermillRateLimitException, ("PapermillRateLimitException",)), | ||
( | ||
exceptions.PapermillOptionalDependencyException, | ||
("PapermillOptionalDependencyException",), | ||
), | ||
], | ||
) | ||
def test_exceptions_are_unpickleable(temp_file, exc, args): | ||
"""Ensure exceptions can be unpickled""" | ||
err = exc(*args) | ||
with open(temp_file.name, 'wb') as fd: | ||
pickle.dump(err, fd) | ||
# Read the Pickled File | ||
temp_file.seek(0) | ||
data = temp_file.read() | ||
pickled_err = pickle.loads(data) | ||
assert str(pickled_err) == str(err) |