aws configure set s3.* can raise UnboundLocalError when updating nested config blocks

未关闭 适合新手
#10,348 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@fallintoplace 已经在做这个了。

开始于 2026年5月24日。

  • #10349 来自 @fallintoplace —— 未关闭
  • #10598 来自 @krantboy —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
aws, python
领域
cli

调研方向

从 awscli/customizations/configure/writer.py 开始,重点查看 ConfigFileWriter._update_subattributes(),并检查 tests/unit/customizations/configure/test_writer.py 中已有的用例。运行 writer 测试,并为为空的嵌套块、注释和紧接着的节标题添加覆盖;完成的标准是更新 s3.signature_version 不再引发错误,并保留预期的嵌套配置。

由索引模型根据 Issue 内容生成。

描述

bug configure p3
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.14
  • develop @ 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

aws/aws-cli 的其他 Issue

查看 aws/aws-cli 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。