-
Notifications
You must be signed in to change notification settings - Fork 421
Error: Using Batch processing with a Pydantic models doesn't folllow under the main idea of batch processing #2091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
@LuckIlNe thank you so much for this super detailed bug report! There was a reason before we added Pydantic support, so we should definitely push that line within the try block as a fix. Feel free to make a PR and we can review, amend any necessary details, and merge it tomorrow morning (CET tz). I'm working on a new Batch improved experience tomorrow and can prioritise this bugfix if you're tight on bandwidth. Thank you! |
…n pill) #2091 (#2099) Co-authored-by: heitorlessa <[email protected]>
Notes for maintainers: Paid additional tech debts as part of this PR
|
|
* develop: fix(batch): handle early validation errors for pydantic models (poison pill) aws-powertools#2091 (aws-powertools#2099) update changelog with latest changes docs(homepage): remove banner for end-of-support v1 (aws-powertools#2098) chore(deps-dev): bump aws-cdk-lib from 2.72.1 to 2.73.0 (aws-powertools#2097) chore(deps-dev): bump filelock from 3.10.7 to 3.11.0 (aws-powertools#2094) chore(deps-dev): bump coverage from 7.2.2 to 7.2.3 (aws-powertools#2092) chore(deps-dev): bump aws-cdk from 2.72.1 to 2.73.0 (aws-powertools#2093) chore(deps-dev): bump mypy-boto3-cloudformation from 1.26.60 to 1.26.108 (aws-powertools#2095) Signed-off-by: heitorlessa <[email protected]>
This is now released under 2.12.0 version! |
Expected Behaviour
Lambda shouldn't failure if there is at least one successful record and return
{batchItemFailures: [...] }
in the example the result of the lambda should be like this:
{ "batchItemFailures": [ { "itemIdentifier": "messageId-2" } ] }
Current Behaviour
Code throw exception without processing all batches
Traceback (most recent call last): File "C:\Users\Crumpet\Desktop\AWS\powertools\model_test.py", line 90, in <module> lambda_handler(event,{}) File "C:\Users\Crumpet\AppData\Local\Programs\Python39\lib\site-packages\aws_lambda_powertools\tracing\tracer.py", line 305, in decorate response = lambda_handler(event, context, **kwargs) File "C:\Users\Crumpet\Desktop\AWS\powertools\model_test.py", line 42, in lambda_handler processed_messages: List[Union[SuccessResponse, FailureResponse]] = processor.process() File "C:\Users\Crumpet\AppData\Local\Programs\Python39\lib\site-packages\aws_lambda_powertools\utilities\batch\base.py", line 97, in process return [self._process_record(record) for record in self.records] File "C:\Users\Crumpet\AppData\Local\Programs\Python39\lib\site-packages\aws_lambda_powertools\utilities\batch\base.py", line 97, in <listcomp> return [self._process_record(record) for record in self.records] File "C:\Users\Crumpet\AppData\Local\Programs\Python39\lib\site-packages\aws_lambda_powertools\utilities\batch\base.py", line 474, in _process_record data = self._to_batch_type(record=record, event_type=self.event_type, model=self.model) File "C:\Users\Crumpet\AppData\Local\Programs\Python39\lib\site-packages\aws_lambda_powertools\utilities\batch\base.py", line 347, in _to_batch_type return model.parse_obj(record) File "pydantic\main.py", line 526, in pydantic.main.BaseModel.parse_obj File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__ pydantic.error_wrappers.ValidationError: 1 validation error for OrderSqsRecord body -> item value is not a valid dict (type=type_error.dict)
Code snippet
Possible Solution
I think it can be easily fixed if we add code for bring to the model under try section (https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/aws_lambda_powertools/utilities/batch/base.py#L474)
But perhaps there are some reasons because of which they decided not to do so. Please share your thoughts
Steps to Reproduce
You can try code snippet. also you can try any test case where you have more than two records in one batch, and one record doesn't follow under your model
AWS Lambda Powertools for Python version
latest
AWS Lambda function runtime
3.9
Packaging format used
PyPi
Debugging logs
The text was updated successfully, but these errors were encountered: