-
Notifications
You must be signed in to change notification settings - Fork 402
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
Feature request: Fix inconsistency between BatchProcessor success_handler and failure_handler call arguments #2816
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @duc00! Thank you for opening this issue. I am moving this issue to pending review to work on this by early next week. |
hey @duc00, it makes sense but it's a breaking change. The reason we didn't do that back (2020) then was that Batch Processing predated both Parser (Pydantic models) and Event Source Data Classes. Changing even to a SQSRecord would've caused customers tests or any custom processor to fail. While I agree with the inconsistency and dislike it very much, changing now could break several customers and we're overly conscious of that. The reason Moving forward Tentatively, we might launch v3 by the end of the year due to Python 3.7 EOL in Lambda. Until then, we'd be happy to have a flag to override this behaviour, then make the default in v3. If you have an idea for a flag or would like to make a PR to it we'd be happy to guide you. Alternative We could pay another tech debt and start specialized Batch Processors (e.g., |
Hi @heitorlessa, thank you for your answer. It makes perfect sense. I am fine for now instantiating the Pydantic model within I would however suggest we mention this is the doc. I could write a PR for this. How does this alternative sound? Thanks! |
absolutely and thank you for offering the PR ;) Let me know once is out and we can merge it quickly. |
I just remembered another scenario that would be difficult to always have a model as argument for For Pydantic Models, a poison pill/malformed payload would prevent it to become an actual model. To prevent failing the entire batch, we handle that gracefully and convert to the closest known Event Source Data Class to allow failure collection. If we were to have an union and/or a parameter, it could confuse non-experienced customers. Record value when model validation worked but batch item failed for another reason Record value when model validation failed |
I've just put a PR with several improvements to Batch documentation and credited accordingly. I created sample outputs for this exact area - let me know if this helps (your PR will tackle another part IIRC). |
This is what I understood, and this is fine as we can deal with the Pydantic model's type in |
Thanks @heitorlessa, I will take a look later today or tomorrow. |
🤦🏻 yes, sorry, been too deep in the woods rewriting the docs that I forgot the |
@heitorlessa, I've just opened a new PR for adding details to |
Just merged, thank you so much @duc00 for this quality contribution. Already available in our stage docs: https://docs.powertools.aws.dev/lambda/python/stage/utilities/batch/#extending-batchprocessor It'll go to prod in our next release |
|
Use case
As mentioned in BatchProcessor's documentation (https://docs.powertools.aws.dev/lambda/python/latest/utilities/batch/#create-your-own-partial-processor), BatchProcessor can be extended by overriding
success_handler
andfailure_handler
methods:Reading this, I see and understand that the record is passed to the function as a Pydantic model. I would thus expect
success_handler
to take the same type of record asfailure_handler
. That is not currently the case, as record is passed as raw dict data in BatchProcessor's_process_record
function:powertools-lambda-python/aws_lambda_powertools/utilities/batch/base.py
Lines 485 to 502 in 021076e
In my opinion,
record
args should be homogeneous between the two functions, or otherwise devs wanting to overridesuccess_handler
will encounter errors at runtime, have to dig in this tool's source code and understand the subtlety (like I did).Solution/User Experience
First solution would be to add an example for
success_handler
in the documentation (https://docs.powertools.aws.dev/lambda/python/latest/utilities/batch/#extending-batchprocessor). This would notify developers of the differences between the functions' signature.Second solution would be to pass the Pydantic model as
record
tosuccess_handler
. This should be a pretty straightforward change in the source code since this structure is already instantiated in_process_record
. This would make the tool more homogeneous as well as improve experience in using the record's attributes insuccess_handler
.Alternative solutions
No response
Acknowledgment
The text was updated successfully, but these errors were encountered: