Bug: validate() raises raw jmespath ParseError instead of InvalidEnvelopeExpressionError for most malformed envelopes
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
issue によると LexerError、TypeError、UnicodeError が捕捉される jmespath_utils.query() から始めてください。validator がクエリエラーをどのように変換するかを確認し、tests/functional/validator 以下の機能テストを確認してください。列挙された不正な envelope のケースを追加し、それらが InvalidEnvelopeExpressionError を送出することと、カスタム関数の動作が引き続きテストでカバーされることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
Expected Behaviour
validate() and the @validator decorator document InvalidEnvelopeExpressionError "when JMESPath expression to unwrap event is invalid", and the exception documents itself as raised "When JMESPath fails to parse expression". So any envelope with a JMESPath syntax error should raise InvalidEnvelopeExpressionError.
Current Behaviour
Only a tokenizer error (LexerError, e.g. an unclosed quote) is converted. Every other syntax error escapes as jmespath's own exception, so except InvalidEnvelopeExpressionError doesn't catch it:
| envelope | raised |
|---|---|
powertools_json(data |
jmespath.exceptions.IncompleteExpressionError |
powertools_json(data, data) |
jmespath.exceptions.ArityError |
data. |
jmespath.exceptions.ParseError |
powertools_json("data) |
InvalidEnvelopeExpressionError (documented) |
jmespath_utils.query() catches (LexerError, TypeError, UnicodeError). LexerError is one subclass of ParseError; IncompleteExpressionError and ArityError are its siblings.
Code snippet
import jmespath.exceptions
from aws_lambda_powertools.utilities.validation import InvalidEnvelopeExpressionError, validate
schema = {"type": "object", "properties": {"message": {"type": "string"}}, "required": ["message"]}
event = {"data": '{"message": "hello"}'}
for envelope in ["powertools_json(data", "powertools_json(data, data)", "data.", 'powertools_json("data)']:
try:
validate(event=event, schema=schema, envelope=envelope)
except InvalidEnvelopeExpressionError:
print(f"{envelope!r}: InvalidEnvelopeExpressionError")
except jmespath.exceptions.JMESPathError as e:
print(f"{envelope!r}: raw {type(e).__name__}")
Possible Solution
Catch jmespath.exceptions.ParseError (the base class of LexerError, IncompleteExpressionError and ArityError) instead of LexerError in jmespath_utils.query(). One line, plus a parametrized functional test in tests/functional/validator. The new cases fail on develop and pass with the change.
I left UnknownFunctionError alone: test_custom_jmespath_function_overrides_builtin_functions pins that it surfaces as-is when custom functions replace the built-ins.
I have this ready on a branch and can open a PR once this is triaged: https://github.com/khaledix3/powertools-lambda-python/compare/develop...fix/jmespath-invalid-expression-error
One compatibility note: code that catches jmespath.exceptions.ParseError around validate() for these cases would need to catch InvalidEnvelopeExpressionError instead, which is what the docs already say to catch. Happy to follow whatever you prefer under ADR 0006.
Steps to Reproduce
- Run the snippet above on
develop(0bbc252, version 3.41.0). - Only
powertools_json("data)printsInvalidEnvelopeExpressionError; the other three print a raw jmespath exception.
Did you run the reproduction yourself?
Yes, I ran it and saw the failure
Powertools for AWS Lambda (Python) version
3.41.0 (develop @ 0bbc252)
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs
'powertools_json(data': raw IncompleteExpressionError
'powertools_json(data, data)': raw ArityError
'data.': raw ParseError
'powertools_json("data)': InvalidEnvelopeExpressionError
- 主要言語
- Python
- スター
- 3.3k
- フォーク
- 511
- 平均マージ
- 2日 23時間
- マージ済み PR(30日)
- 50
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
aws-powertools/powertools-lambda-python のほかの issue
-
Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mappingオープンbug triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
aws-powertools/powertools-lambda-python#8948 ·
メンテナーはふだん 1 日以内に返信
-
Docs: child Logger without a parent uses the root log level since #8842対応中かも @rdxrahul12 が今日担当しました。 オープンdocumentation triage
難易度 1/5 1〜3時間 初心者へのやさしさ 85/100
aws-powertools/powertools-lambda-python#8935 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Bug: Set-Cookie values passed as a header are comma-joined into one invalid header on HTTP API and Function URL responses対応中かも @saquibjawedbit が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
aws-powertools/powertools-lambda-python#8921 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Bug: SQSRecord.decoded_nested_sns_event raises KeyError on SNS messages delivered to SQS対応中かも @hyeonsang010716 が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
aws-powertools/powertools-lambda-python#8913 ·
メンテナーはふだん 1 日以内に返信
-
Bug: Metrics keeps dimensions and metadata from an invocation that added no metrics対応中かも @hyeonsang010716 が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
aws-powertools/powertools-lambda-python#8911 ·
メンテナーはふだん 1 日以内に返信
aws-powertools/powertools-lambda-python の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
litestar-org/sqlspec#946 ·
メンテナーはふだん 1 日以内に返信
-
area:cli area:docs Platform vdr
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NVIDIA-NeMo/Gym#7192 ·
メンテナーはふだん 2 日以内に返信
-
SofyaBotオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
ai-robots-txt/ai.robots.txt#324 ·
-
[Resource]: Dashbarオープンresource-submission validation-passed
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
hesreallyhim/awesome-claude-code#3821 · コメント 1 件 ·
-
bug good first issue help wanted level 1 wocs
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
GianlucaBave/murmury#169 ·
メンテナーはふだん 1 日以内に返信