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

Aperta Adatta ai principianti
#10,348 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@fallintoplace ci sta già lavorando.

Dal 24/5/2026.

  • #10349 di @fallintoplace — aperta
  • #10598 di @krantboy — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
aws, python
Ambito
cli

Direzione di ricerca

Inizia da awscli/customizations/configure/writer.py, in particolare da ConfigFileWriter._update_subattributes(), e rivedi i casi esistenti in tests/unit/customizations/configure/test_writer.py. Esegui i test del writer e aggiungi la copertura per blocchi annidati vuoti, commenti e un'intestazione di sezione immediata; il lavoro è completato quando l'aggiornamento di s3.signature_version non genera più errori e preserva la configurazione annidata prevista.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
17.4k
Fork
4.8k
Merge medio
4g 3h
PR unite (30g)
64

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di aws/aws-cli

Tutte le issue di aws/aws-cli

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.