Skip to content

fix(batch): handle early validation errors for pydantic models (poison pill) #2091 #2099

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

Merged
merged 12 commits into from
Apr 7, 2023

Conversation

nepshshsh
Copy link
Contributor

@nepshshsh nepshshsh commented Apr 7, 2023

Issue number: #2091

Summary

Lambda shouldn't failure if there is at least one successful record and return {batchItemFailures: [...] } when we use pydantic model check. For resolution, checking model function has been moved under try section in batch processing for BatchProcessor and AsyncBatchProcessor classes

Changes

Move pydantic model check line under try section in batch processing.

User experience

Now only records which aren't pass pydantic modeling check will mark as failed records

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@nepshshsh nepshshsh requested a review from a team as a code owner April 7, 2023 09:07
@nepshshsh nepshshsh requested review from leandrodamascena and removed request for a team April 7, 2023 09:07
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 7, 2023

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our AWS Lambda Powertools Discord: Invite link

@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 7, 2023
@heitorlessa
Copy link
Contributor

Looking

@heitorlessa heitorlessa requested review from heitorlessa and removed request for leandrodamascena April 7, 2023 09:10
@github-actions github-actions bot added the bug Something isn't working label Apr 7, 2023
@heitorlessa
Copy link
Contributor

Sending a few fixes and we can merge and add it to the release

@boring-cyborg boring-cyborg bot added the tests label Apr 7, 2023
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 7, 2023
@nepshshsh
Copy link
Contributor Author

Thank you @heitorlessa, now it looks much better

@codecov-commenter
Copy link

codecov-commenter commented Apr 7, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (ec1b346) 97.45% compared to head (b4cca25) 97.45%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2099   +/-   ##
========================================
  Coverage    97.45%   97.45%           
========================================
  Files          146      146           
  Lines         6748     6767   +19     
  Branches       477      483    +6     
========================================
+ Hits          6576     6595   +19     
  Misses         136      136           
  Partials        36       36           
Impacted Files Coverage Δ
aws_lambda_powertools/utilities/batch/base.py 95.58% <100.00%> (+0.45%) ⬆️
...wertools/utilities/idempotency/persistence/base.py 99.39% <100.00%> (ø)
...ools/utilities/idempotency/persistence/dynamodb.py 100.00% <100.00%> (ø)
...bda_powertools/utilities/parser/models/dynamodb.py 100.00% <100.00%> (ø)
...mbda_powertools/utilities/parser/models/kinesis.py 100.00% <100.00%> (ø)
...s_lambda_powertools/utilities/parser/models/sqs.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 7, 2023
@heitorlessa
Copy link
Contributor

Just need to finish the async and we can merge it ;) THANK YOU for spotting this subtle but important bug and taking the initiative all along.

@heitorlessa heitorlessa changed the title fix(batch): Processing batch with pydantic models #2091 fix(batch): handle early validation errors for pydantic models (poison pill) #2091 Apr 7, 2023
@heitorlessa
Copy link
Contributor

Done - just waiting for CI to confirm everything works as expected and I'll merge it.

Took longer than expected as we had a bunch of tech debts to pay in test authoring - all cleaned up now.

PS: Working on a better DX (backwards compatible) for Batch processing to reduce boilerplate in parallel: #2090.

@heitorlessa
Copy link
Contributor

Thank you so much @LuckIlNe for kicking this off. Bunch of tech debts we've wanted to address so we took the liberty to do it too. Mypy/Static typing linters will no also no longer complain about the use of body: Json[Model] so it'll also cut some boilerplate for you: https://github.com/awslabs/aws-lambda-powertools-python/pull/2099/files#diff-24525fde52e7050cebd8041038fb1ca36688c0f14e16c2f3960fa178c0e1d63fR20

Merging!

@heitorlessa heitorlessa merged commit c3e25d6 into aws-powertools:develop Apr 7, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 7, 2023

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

heitorlessa added a commit to heitorlessa/aws-lambda-powertools-python that referenced this pull request Apr 7, 2023
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: Using Batch processing with a Pydantic models doesn't folllow under the main idea of batch processing
3 participants