diff --git a/botocore/exceptions.py b/botocore/exceptions.py index 294bbf4020..0013072c98 100644 --- a/botocore/exceptions.py +++ b/botocore/exceptions.py @@ -477,6 +477,12 @@ def __init__(self, name, reason, last_response): super().__init__(name=name, reason=reason) self.last_response = last_response + def __reduce__(self): + return _exception_from_packed_args, ( + self.__class__, + (self.kwargs['name'], self.kwargs['reason'], self.last_response), + ) + class IncompleteReadError(BotoCoreError): """HTTP response did not return expected number of bytes.""" diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py index c7000d1b55..1a8e31f36b 100644 --- a/tests/unit/test_exceptions.py +++ b/tests/unit/test_exceptions.py @@ -11,6 +11,7 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. +import copy import pickle import botocore.awsrequest @@ -167,3 +168,31 @@ def test_http_client_error(self): self.assertIsInstance( unpickled_exception.response, botocore.awsrequest.AWSResponse ) + + def test_waiter_error(self): + exception = botocore.exceptions.WaiterError( + name='MyWaiter', + reason='MyReason', + last_response={'State': 'pending'}, + ) + unpickled_exception = pickle.loads(pickle.dumps(exception)) + self.assertIsInstance( + unpickled_exception, botocore.exceptions.WaiterError + ) + self.assertEqual(str(unpickled_exception), str(exception)) + self.assertEqual(unpickled_exception.kwargs, exception.kwargs) + self.assertEqual( + unpickled_exception.last_response, exception.last_response + ) + + def test_waiter_error_can_be_copied(self): + exception = botocore.exceptions.WaiterError( + name='MyWaiter', + reason='MyReason', + last_response={'State': 'pending'}, + ) + copied_exception = copy.copy(exception) + self.assertIsInstance(copied_exception, botocore.exceptions.WaiterError) + self.assertEqual(str(copied_exception), str(exception)) + self.assertEqual(copied_exception.kwargs, exception.kwargs) + self.assertEqual(copied_exception.last_response, exception.last_response)