Bug: Cookie Expires labels a non-UTC aware datetime as GMT without converting it
维护者通常 1 天内回复
@LemonCondor 已经在做这个了。
开始于 2026年10月29日。
评估
调研方向
从 aws_lambda_powertools/shared/cookies.py 中的 Cookie._format_date 以及 tests/unit/test_cookie_class.py 中提到的回归测试开始。运行该测试,以确认当前格式化后的 header 会保留时区偏移。完成标准是:带时区的 datetime 以 UTC 输出,naive datetime 保持当前行为,并且回归测试通过。
由索引模型根据 Issue 内容生成。
描述
Expected Behaviour
A Cookie whose expires is a timezone-aware datetime should send that instant in GMT, as RFC 6265 requires for Expires. datetime(2026, 1, 1, 12, tzinfo=timezone(timedelta(hours=2))) is 10:00 UTC, so the header should read Expires=Thu, 01 Jan 2026 10:00:00 GMT.
Current Behaviour
Cookie._format_date formats the datetime with strftime and a hard-coded GMT suffix, without converting it to UTC first. The local wall-clock time is labelled GMT, so the cookie expires earlier or later by the UTC offset: Expires=Thu, 01 Jan 2026 12:00:00 GMT.
Code snippet
from datetime import datetime, timedelta, timezone
from aws_lambda_powertools.shared.cookies import Cookie
cookie = Cookie("a", "b", expires=datetime(2026, 1, 1, 12, tzinfo=timezone(timedelta(hours=2))))
print(str(cookie)) # a=b; Secure; Expires=Thu, 01 Jan 2026 12:00:00 GMT
Possible Solution
Convert an aware datetime to UTC before formatting (expires.astimezone(timezone.utc)); naive datetimes keep today's behaviour. I have this fix with a regression test in tests/unit/test_cookie_class.py (fails on develop, passes with the change) and can open a PR once this is triaged.
Steps to Reproduce
Run the snippet above on develop (5785377).
Powertools for AWS Lambda (Python) version
latest (3.37.0, develop)
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs
N/A
- 主要语言
- 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 于 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
-
难度 2/5 1-3 小时 新手友好度 82/100
microsoft/markitdown#2820 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
yt-project/yt#5624 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
NousResearch/hermes-agent#148376 ·
维护者通常 1 天内回复