Bug: validate() raises raw jmespath ParseError instead of InvalidEnvelopeExpressionError for most malformed envelopes
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
Hướng nghiên cứu
Bắt đầu tại jmespath_utils.query(), nơi issue cho biết LexerError, TypeError và UnicodeError được bắt. Kiểm tra cách validator chuyển đổi lỗi truy vấn và xem lại các bài kiểm thử chức năng trong tests/functional/validator. Thêm các trường hợp cho những envelope sai định dạng được liệt kê và xác nhận chúng gây ra InvalidEnvelopeExpressionError, đồng thời hành vi của hàm tùy chỉnh vẫn được kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 3.3k
- Fork
- 511
- Merge trung bình
- 2 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 50
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws-powertools/powertools-lambda-python
-
Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mappingĐang mởbug triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
aws-powertools/powertools-lambda-python#8948 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Docs: child Logger without a parent uses the root log level since #8842Có thể đã có người làm @rdxrahul12 đã nhận hôm nay. Đang mởdocumentation triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
aws-powertools/powertools-lambda-python#8935 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: Set-Cookie values passed as a header are comma-joined into one invalid header on HTTP API and Function URL responsesCó thể đã có người làm @saquibjawedbit đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
aws-powertools/powertools-lambda-python#8921 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: SQSRecord.decoded_nested_sns_event raises KeyError on SNS messages delivered to SQSCó thể đã có người làm @hyeonsang010716 đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
aws-powertools/powertools-lambda-python#8913 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: Metrics keeps dimensions and metadata from an invocation that added no metricsCó thể đã có người làm @hyeonsang010716 đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
aws-powertools/powertools-lambda-python#8911 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của aws-powertools/powertools-lambda-python
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
litestar-org/sqlspec#946 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:cli area:docs Platform vdr
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NVIDIA-NeMo/Gym#7192 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
SofyaBotĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
ai-robots-txt/ai.robots.txt#324 ·
-
[Resource]: DashbarĐang mởresource-submission validation-passed
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
hesreallyhim/awesome-claude-code#3821 · 1 bình luận ·
-
bug good first issue help wanted level 1 wocs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
GianlucaBave/murmury#169 ·
Maintainer thường phản hồi trong vòng 1 ngày