From 1984c6353da59e62b708d6b26d8fdcafc5de5bdd Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Mon, 16 May 2022 10:19:07 -0700 Subject: [PATCH 1/3] fix(batch): allow child_exceptions to be none Change: - Allow for child_exceptions being none in format_exceptions fixes #1203 --- aws_lambda_powertools/utilities/batch/exceptions.py | 2 +- tests/functional/test_utilities_batch.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/batch/exceptions.py b/aws_lambda_powertools/utilities/batch/exceptions.py index d90c25f12bc..e616ce02ab7 100644 --- a/aws_lambda_powertools/utilities/batch/exceptions.py +++ b/aws_lambda_powertools/utilities/batch/exceptions.py @@ -12,7 +12,7 @@ class BaseBatchProcessingError(Exception): def __init__(self, msg="", child_exceptions: Optional[List[ExceptionInfo]] = None): super().__init__(msg) self.msg = msg - self.child_exceptions = child_exceptions + self.child_exceptions = child_exceptions or [] def format_exceptions(self, parent_exception_str): exception_list = [f"{parent_exception_str}\n"] diff --git a/tests/functional/test_utilities_batch.py b/tests/functional/test_utilities_batch.py index a5e1e706437..d88c958c056 100644 --- a/tests/functional/test_utilities_batch.py +++ b/tests/functional/test_utilities_batch.py @@ -908,3 +908,7 @@ def lambda_handler(event, context): # THEN raise BatchProcessingError assert "All records failed processing. " in str(e.value) + + +def test_child_exceptions_is_none(): + assert SQSBatchProcessingError("").format_exceptions("example") == "example\n" From 8b53f5537e97de04bf49e05f0be44a2c3ab7784a Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Tue, 17 May 2022 20:56:35 -0700 Subject: [PATCH 2/3] fix: adjust PR --- aws_lambda_powertools/utilities/batch/exceptions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws_lambda_powertools/utilities/batch/exceptions.py b/aws_lambda_powertools/utilities/batch/exceptions.py index e616ce02ab7..65afd91801b 100644 --- a/aws_lambda_powertools/utilities/batch/exceptions.py +++ b/aws_lambda_powertools/utilities/batch/exceptions.py @@ -12,11 +12,11 @@ class BaseBatchProcessingError(Exception): def __init__(self, msg="", child_exceptions: Optional[List[ExceptionInfo]] = None): super().__init__(msg) self.msg = msg - self.child_exceptions = child_exceptions or [] + self.child_exceptions = child_exceptions def format_exceptions(self, parent_exception_str): exception_list = [f"{parent_exception_str}\n"] - for exception in self.child_exceptions: + for exception in self.child_exceptions or []: extype, ex, tb = exception formatted = "".join(traceback.format_exception(extype, ex, tb)) exception_list.append(formatted) From f1eab1733cfabd1262757426208f562426e46207 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Wed, 18 May 2022 12:04:29 -0700 Subject: [PATCH 3/3] chore: smaller test for review --- tests/functional/test_utilities_batch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_utilities_batch.py b/tests/functional/test_utilities_batch.py index d88c958c056..757d2ddc398 100644 --- a/tests/functional/test_utilities_batch.py +++ b/tests/functional/test_utilities_batch.py @@ -911,4 +911,4 @@ def lambda_handler(event, context): def test_child_exceptions_is_none(): - assert SQSBatchProcessingError("").format_exceptions("example") == "example\n" + assert str(SQSBatchProcessingError()) == "\n"