aws configure set s3.* can raise UnboundLocalError when updating nested config blocks
维护者通常 2 天内回复
评估
调研方向
从 awscli/customizations/configure/writer.py 开始,重点查看 ConfigFileWriter._update_subattributes(),并检查 tests/unit/customizations/configure/test_writer.py 中已有的用例。运行 writer 测试,并为为空的嵌套块、注释和紧接着的节标题添加覆盖;完成的标准是更新 s3.signature_version 不再引发错误,并保留预期的嵌套配置。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
aws configure set s3.signature_version s3v4 can crash when the target config already has a nested s3 = block and the next line is not another option line.
I reproduced this with all of the following existing config shapes:
- an empty nested block
- a comment immediately after
s3 = - an immediate next section header after
s3 =
The crash comes from ConfigFileWriter._update_subattributes() reading current_indent even when OPTION_REGEX did not match the current line.
Regression Issue
This does not look like a recent regression. git blame shows _update_subattributes() was introduced with this behavior in 9c2fd8098a.
Expected Behavior
Updating a nested config value should append or update the nested key without crashing.
For example, starting from:
[default]
s3 =
# comment
addressing_style = path
setting s3.signature_version should produce:
[default]
s3 =
# comment
addressing_style = path
signature_version = s3v4
Current Behavior
An uncaught traceback is raised:
Traceback (most recent call last):
File "/Users/hoangvu/Code/OSS/aws-cli/awscli/customizations/configure/writer.py", line 115, in update_config
self._update_section_contents(contents, section_name, new_values)
File "/Users/hoangvu/Code/OSS/aws-cli/awscli/customizations/configure/writer.py", line 203, in _update_section_contents
j = self._update_subattributes(
File "/Users/hoangvu/Code/OSS/aws-cli/awscli/customizations/configure/writer.py", line 231, in _update_subattributes
if starting_indent == current_indent or \
^^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'current_indent' where it is not associated with a value
Reproduction Steps
Minimal reproducer:
from awscli.customizations.configure.writer import ConfigFileWriter
import os
import tempfile
fd, path = tempfile.mkstemp()
os.close(fd)
with open(path, "w") as f:
f.write("[default]\ns3 =\n# comment\n addressing_style = path\n")
ConfigFileWriter().update_config(
{"__section__": "default", "s3": {"signature_version": "s3v4"}},
path,
)
This also reproduces with:
[default]
s3 =
and:
[default]
s3 =
[profile other]
region = us-east-1
Possible Solution
Handle non-option lines before comparing indentation, or initialize current_indent safely.
For example, _update_subattributes() could skip lines where OPTION_REGEX does not match, while still treating a new section header as the boundary for inserting new nested values.
It would also be helpful to add regression tests in tests/unit/customizations/configure/test_writer.py for:
- empty nested blocks
- comments after
s3 = - section headers immediately after
s3 =
Additional Information/Context
I reproduced this against the current develop checkout:
aws-cli/1.45.14develop@b698a6a77- macOS 26.5 arm64
- Python 3.13.2
The user-facing path appears to be aws configure set s3.signature_version ..., but the minimal reproducer above avoids unrelated environment/setup dependencies.
CLI version used
aws-cli/1.45.14
Environment details (OS name and version, etc.)
macOS 26.5 arm64, Python 3.13.2
- 主要语言
- Python
- 星标
- 17.4k
- 派生
- 4.8k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 64
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aws/aws-cli 的其他 Issue
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
feature-request login p2
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
aws history show/list: UnboundLocalError instead of clear error when pager fails to start可能已有人在做 @Adityaj0 于 85 天前认领。 未关闭needs-triage
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
CodeArtifact login: auth token leaked unredacted in CommandFailedError via subprocess stderr可能已有人在做 @PANYAMHEMANTH 于 7 天前认领。 未关闭codeartifact login investigating p2
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 2 天内回复
-
Refactor: drop redundant list() wrapper around sorted() in formatter.py/text.py可能已有人在做 @Adityaj0 于 88 天前认领。 未关闭feature-request p3
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 2 天内回复
相似的 Issue
-
needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
gke-labs/kube-agents#5671 ·
维护者通常 1 天内回复
-
documentation next-release v0.9.6
难度 1/5 1 小时以内 新手友好度 88/100
khuisman/mcp-gee-sweet#1446 ·
维护者通常 1 天内回复
-
model:sonnet runtime:claude security size:S
难度 2/5 1-3 小时 新手友好度 75/100
FootprintAI/Containarium#3671 ·
维护者通常 1 天内回复
-
HolidayBase: reassigning `language` does not re-initialize translations or re-populate holidays可能已有人在做 @shikhabhadoria 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
vacanza/holidays#4116 · 1 条评论 ·
维护者通常 1 天内回复
-
bug CLI exec
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复