Bug: idempotent functions return None on replay when the stored response is falsy (0, False, "", [], {})
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
Expected Behaviour
When an idempotent function returns a falsy value (0, False, "", [], {}), a retry with the same payload should return that same value from the persistence store.
Current Behaviour
The first call returns the value and it is stored correctly, but every replay returns None.
IdempotencyHandler._handle_for_status reads the stored response with:
serialized_response = self.output_serializer.from_dict(response_dict) if response_dict else None
so any falsy response_dict becomes None. #8090 pointed out this line together with the write path in _get_function_response. The write path was changed to is not None, but the read path still uses a truthiness check, so the value is saved and then dropped on replay.
Code snippet
from aws_lambda_powertools.utilities.idempotency import idempotent_function
from aws_lambda_powertools.utilities.idempotency.exceptions import (
IdempotencyItemAlreadyExistsError,
IdempotencyItemNotFoundError,
)
from aws_lambda_powertools.utilities.idempotency.persistence.base import BasePersistenceLayer, DataRecord
class InMemoryPersistenceLayer(BasePersistenceLayer):
def __init__(self):
super().__init__()
self.records = {}
def _get_record(self, idempotency_key) -> DataRecord:
if idempotency_key not in self.records:
raise IdempotencyItemNotFoundError
return self.records[idempotency_key]
def _put_record(self, data_record: DataRecord) -> None:
if data_record.idempotency_key in self.records:
raise IdempotencyItemAlreadyExistsError
self.records[data_record.idempotency_key] = data_record
def _update_record(self, data_record: DataRecord) -> None:
self.records[data_record.idempotency_key] = data_record
def _delete_record(self, data_record: DataRecord) -> None:
self.records.pop(data_record.idempotency_key, None)
persistence_layer = InMemoryPersistenceLayer()
@idempotent_function(data_keyword_argument="order", persistence_store=persistence_layer)
def count_items(order):
return len(order["items"])
order = {"order_id": "o-1", "items": []}
print(count_items(order=order)) # 0
print(count_items(order=order)) # None, expected 0
I see the same with CachePersistenceLayer on a real Redis server: 0, False, "", [] and {} all come back as None on replay, while None and truthy values are returned correctly.
Possible Solution
Use is not None, matching the write path:
serialized_response = self.output_serializer.from_dict(response_dict) if response_dict is not None else None
DataRecord.response_json_as_dict() already returns None when there is no stored data, and a function that returns None is stored as null, so that case keeps returning None.
Steps to Reproduce
Run the snippet above. Any persistence layer is affected, since the check is in the shared handler.
Powertools for AWS Lambda (Python) version
latest (3.37.0, also on develop)
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs
N/A, the replay returns None without an error
- 主要言語
- Python
- スター
- 3.3k
- フォーク
- 511
- 平均マージ
- 3日 4時間
- マージ済み PR(30日)
- 98
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
aws-powertools/powertools-lambda-python のほかの issue
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocation対応中かも @lechakrawarthy が 2 日前に担当しました。 オープン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 が 2 日前に担当しました。 オープン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 が 2 日前に担当しました。 オープン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 が 2 日前に担当しました。 オープンbug good first issue help wanted idempotency
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
aws-powertools/powertools-lambda-python#8725 · コメント 6 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key value対応中かも @sumedh-aerram が 2 日前に担当しました。 オープン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
-
bump patch
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
autowarefoundation/autoware_carla_scenario#1321 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
QuantConnect/Documentation#2838 ·
メンテナーはふだん 1 日以内に返信
-
get_all_subclasses must deduplicate by class identity対応中かも @Gambit-Checkmate が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 15 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
awslabs/route53-dynamic-dns-with-lambda#67 · コメント 1 件 ·