Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions aws_lambda_powertools/utilities/batch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
KinesisStreamRecord,
)
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
from aws_lambda_powertools.utilities.parser import ValidationError
from aws_lambda_powertools.utilities.typing import LambdaContext

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -496,9 +495,15 @@ def _process_record(self, record: dict) -> Union[SuccessResponse, FailureRespons
result = self.handler(record=data)

return self.success_handler(record=record, result=result)
except ValidationError:
return self._register_model_validation_error_record(record)
except Exception:
except Exception as exc:
# NOTE: Pydantic is an optional dependency, but when used and a poison pill scenario happens
# we need to handle that exception differently.
# We check for a public attr in validation errors coming from Pydantic exceptions (subclass or not)
# and we compare if it's coming from the same model that trigger the exception in the first place
model = getattr(exc, "model", None)
if model == self.model:
return self._register_model_validation_error_record(record)

return self.failure_handler(record=data, exception=sys.exc_info())


Expand Down Expand Up @@ -634,7 +639,13 @@ async def _async_process_record(self, record: dict) -> Union[SuccessResponse, Fa
result = await self.handler(record=data)

return self.success_handler(record=record, result=result)
except ValidationError:
return self._register_model_validation_error_record(record)
except Exception:
except Exception as exc:
# NOTE: Pydantic is an optional dependency, but when used and a poison pill scenario happens
# we need to handle that exception differently.
# We check for a public attr in validation errors coming from Pydantic exceptions (subclass or not)
# and we compare if it's coming from the same model that trigger the exception in the first place
model = getattr(exc, "model", None)
if model == self.model:
return self._register_model_validation_error_record(record)

return self.failure_handler(record=data, exception=sys.exc_info())