Bug: SqsFifoPartialProcessor fails the whole batch when a short-circuited record doesn't match the model
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
Expected Behaviour
With SqsFifoPartialProcessor(model=...), once a record fails, the remaining records (or the remaining records of the failed message group with skip_group_on_error=True) should be reported in batchItemFailures, even if one of them doesn't match the model.
Current Behaviour
The short-circuit path converts the record with the customer's model outside of any try:
if fail_entire_batch or fail_group_id:
return self.failure_handler(
record=self._to_batch_type(record, event_type=self.event_type, model=self.model),
exception=...,
)
If that record fails validation, the ValidationError propagates out of process() and the whole invocation fails. The poison-pill handling from #2091 never runs here because it lives in BatchProcessor._process_record, which isn't called for short-circuited records.
As a result the partial batch response is lost and every record is retried, including the ones that were already processed successfully. With skip_group_on_error=True that includes the successful records from other message groups.
(Different code path from #8660, which is about BatchProcessor._process_record.)
Code snippet
from pydantic import BaseModel, Json
from aws_lambda_powertools.utilities.batch import SqsFifoPartialProcessor, process_partial_response
from aws_lambda_powertools.utilities.parser.models import SqsRecordModel
class OrderBody(BaseModel):
order_id: int
class Order(SqsRecordModel):
body: Json[OrderBody]
def make_record(message_id, body, group_id):
return {
"messageId": message_id,
"receiptHandle": "handle",
"body": body,
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1",
"SenderId": "sender",
"ApproximateFirstReceiveTimestamp": "1",
"MessageGroupId": group_id,
"SequenceNumber": "1",
"MessageDeduplicationId": "dedup",
},
"messageAttributes": {},
"md5OfBody": "md5",
"eventSource": "aws:sqs",
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:queue.fifo",
"awsRegion": "us-east-1",
}
def record_handler(record: Order):
if record.body.order_id == 1:
raise RuntimeError("failed to process order")
event = {
"Records": [
make_record("1", '{"order_id": 1}', "group-1"), # fails in the handler
make_record("2", '{"unexpected": 1}', "group-1"), # doesn't match the model
make_record("3", '{"order_id": 3}', "group-2"),
],
}
for skip_group_on_error in (False, True):
processor = SqsFifoPartialProcessor(model=Order, skip_group_on_error=skip_group_on_error)
# Expected: batchItemFailures for 1 and 2 (and 3 when skip_group_on_error=False)
# Actual: pydantic ValidationError for record 2 escapes and fails the invocation
print(process_partial_response(event=event, record_handler=record_handler, processor=processor))
Possible Solution
The short-circuited record is never passed to the record handler, so it only needs to be convertible for failure_handler / _collect_sqs_failures, which already accept event source data classes for poison pills. Two options:
- Fall back to the event source data class when the model conversion fails (keeps
fail_messagesas model instances for valid records, same as today). - Always register short-circuited records as event source data classes. Simpler, but changes the type of entries in
fail_messagesfor customers who inspect them.
I'd go with 1 and add tests for both skip_group_on_error modes. Happy to open a PR.
Steps to Reproduce
Run the snippet above.
Powertools for AWS Lambda (Python) version
latest (develop @ 45f7a4d)
AWS Lambda function runtime
3.11
Packaging format used
PyPi
Debugging logs
No response
- 主要语言
- Python
- 星标
- 3.3k
- 派生
- 511
- 平均合并
- 3 天 8 小时
- 30 天内合并 PR
- 92
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aws-powertools/powertools-lambda-python 的其他 Issue
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocation可能已有人在做 @lechakrawarthy 于 1 天前认领。 未关闭bug good first issue help wanted idempotency
难度 2/5 1-3 小时 新手友好度 85/100
aws-powertools/powertools-lambda-python#8728 · 4 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GET可能已有人在做 @coughlmao 于 1 天前认领。 未关闭bug good first issue help wanted idempotency
难度 2/5 1-3 小时 新手友好度 85/100
aws-powertools/powertools-lambda-python#8727 · 4 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 seconds可能已有人在做 @CJstate 于 1 天前认领。 未关闭bug good first issue help wanted idempotency
难度 2/5 1-3 小时 新手友好度 75/100
aws-powertools/powertools-lambda-python#8726 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashed可能已有人在做 @Neeraj111010 于 1 天前认领。 未关闭bug good first issue help wanted idempotency
难度 2/5 1-3 小时 新手友好度 80/100
aws-powertools/powertools-lambda-python#8725 · 4 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key value可能已有人在做 @sumedh-aerram 于 1 天前认领。 未关闭bug good first issue help wanted idempotency
难度 2/5 1-3 小时 新手友好度 90/100
aws-powertools/powertools-lambda-python#8724 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 aws-powertools/powertools-lambda-python 的全部 Issue
相似的 Issue
-
URLValidator ignores an explicit empty scheme allowlist可能已有人在做 @IlyaKhalafi 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
tortoise/tortoise-orm#2393 ·
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
frappe/frappe_docker#2046 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
-
complete_box_iou_loss / complete_box_iou: NaN gradients for zero-height boxes, NaN for point boxes未关闭
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
AXI SMU SPEC
难度 2/5 1-3 小时 新手友好度 62/100
tenstorrent/tt-oca-harness#3556 ·
维护者通常 1 天内回复