Skip to content

Commit 5ab2ec7

Browse files
committed
fix: mutability bug
1 parent 113a44f commit 5ab2ec7

File tree

1 file changed

+6
-8
lines changed
  • aws_lambda_powertools/utilities/batch

1 file changed

+6
-8
lines changed

aws_lambda_powertools/utilities/batch/base.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def batch_processor(
156156

157157

158158
class BatchProcessor(BasePartialProcessor):
159-
DEFAULT_REPORT = {"batchItemFailures": []}
159+
DEFAULT_RESPONSE: Dict[str, List[Optional[dict]]] = {"batchItemFailures": []}
160160

161161
def __init__(self, event_type: EventType):
162162
"""Process batch and partially report failed items
@@ -168,21 +168,21 @@ def __init__(self, event_type: EventType):
168168
"""
169169
# refactor: Bring boto3 etc. for deleting permanent exceptions
170170
self.event_type = event_type
171-
self.items_to_report: Dict[str, List[Optional[dict]]] = self.DEFAULT_REPORT
171+
self.batch_response = self.DEFAULT_RESPONSE
172172

173173
super().__init__()
174174

175175
def response(self):
176-
"""Response containing batch items that failed processing, if any"""
177-
return self.items_to_report
176+
"""Batch items that failed processing, if any"""
177+
return self.batch_response
178178

179179
def _prepare(self):
180180
"""
181181
Remove results from previous execution.
182182
"""
183183
self.success_messages.clear()
184184
self.fail_messages.clear()
185-
self.items_to_report = self.DEFAULT_REPORT
185+
self.batch_response = self.DEFAULT_RESPONSE
186186

187187
def _process_record(self, record) -> Tuple:
188188
"""
@@ -208,9 +208,7 @@ def _clean(self):
208208
return
209209

210210
messages = self._get_messages_to_report()
211-
self.items_to_report["batchItemFailures"].append(messages)
212-
213-
return self.items_to_report
211+
self.batch_response = {"batchItemFailures": [messages]}
214212

215213
def _has_messages_to_report(self) -> bool:
216214
if self.fail_messages:

0 commit comments

Comments
 (0)