Skip to content

Commit

Permalink
Support pickling of exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
subhashb committed Sep 23, 2021
1 parent 5cb6ded commit b670fd6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/protean/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def __init__(self, messages, **kwargs):
def __str__(self):
return f"{dict(self.messages)}"

def __reduce__(self):
return (ProteanException, (self.messages,))


class ConfigurationError(Exception):
"""Improper Configuration encountered like:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pickle

from protean.exceptions import ObjectNotFoundError


def test_pickling_of_exceptions():
exc = ObjectNotFoundError({"_entity": "foo"})

pickled_exc = pickle.dumps(exc)
unpickled_exc = pickle.loads(pickled_exc)

assert exc.messages == unpickled_exc.messages

0 comments on commit b670fd6

Please sign in to comment.