You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(batch): report records that fail model conversion with non-validation errors - #8662
When converting a record to the customer's model raised something other than the model's ValidationError (Pydantic v2 only wraps ValueError/AssertionError from validators, so e.g. a KeyError escapes as-is), BatchProcessor._process_record and AsyncBatchProcessor._async_process_record called failure_handler(record=data) with data still None. None ended up in fail_messages, and _clean() then crashed in _collect_*_failures with AttributeError: 'NoneType' object has no attribute 'message_id'.
data is None in the except block means the conversion itself failed, so those records now go through the existing _register_model_validation_error_record path from #2091, which converts the raw record to the event source data class and registers it with the original exception.
Tests: a model whose field_validator raises KeyError for one record of three, for the sync and async processors. Both failed with the AttributeError before the change and pass after it; batch.exceptions keeps the original KeyError. tests/functional/batch passes on Linux (Python 3.12), along with ruff, mypy, ty, bandit and xenon.
User experience
Before: one malformed record fails the whole invocation with an AttributeError that hides the real error, and every record in the batch is retried, including the ones that already succeeded.
After: the malformed record is reported in batchItemFailures (as an event source data class, as documented for early model failures) and the rest of the batch is processed normally.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
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 Powertools for AWS Lambda Discord: Invite link
Hi @soujasK, I saw you closed this one. No problem, I just want to understand what you'd prefer. The bug is real and triaged for 3.40.0, and I already worked on it on my side. Do you want to reopen so I review your PR, or should I open a new one myself? Either way is fine, just let me know.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size/MDenotes a PR that changes 30-99 lines, ignoring generated files.tests
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue number: closes #8660
Summary
Changes
When converting a record to the customer's model raised something other than the model's
ValidationError(Pydantic v2 only wrapsValueError/AssertionErrorfrom validators, so e.g. aKeyErrorescapes as-is),BatchProcessor._process_recordandAsyncBatchProcessor._async_process_recordcalledfailure_handler(record=data)withdatastillNone.Noneended up infail_messages, and_clean()then crashed in_collect_*_failureswithAttributeError: 'NoneType' object has no attribute 'message_id'.data is Nonein theexceptblock means the conversion itself failed, so those records now go through the existing_register_model_validation_error_recordpath from #2091, which converts the raw record to the event source data class and registers it with the original exception.Tests: a model whose
field_validatorraisesKeyErrorfor one record of three, for the sync and async processors. Both failed with theAttributeErrorbefore the change and pass after it;batch.exceptionskeeps the originalKeyError.tests/functional/batchpasses on Linux (Python 3.12), along with ruff, mypy, ty, bandit and xenon.User experience
Before: one malformed record fails the whole invocation with an
AttributeErrorthat hides the real error, and every record in the batch is retried, including the ones that already succeeded.After: the malformed record is reported in
batchItemFailures(as an event source data class, as documented for early model failures) and the rest of the batch is processed normally.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.