Skip to content

Fix UnboundLocalError in ConfigFileWriter._update_subattributes for empty nested sections - #10588

Open
Adityaj0 wants to merge 1 commit into
aws:developfrom
Adityaj0:fix/configure-set-empty-nested-section-crash
Open

Fix UnboundLocalError in ConfigFileWriter._update_subattributes for empty nested sections#10588
Adityaj0 wants to merge 1 commit into
aws:developfrom
Adityaj0:fix/configure-set-empty-nested-section-crash

Conversation

@Adityaj0

Copy link
Copy Markdown

Summary

Fixes #10587.

ConfigFileWriter._update_subattributes (used by aws configure set to write into nested config sections like s3/s3api) only assigned current_indent inside the branch where a sub-option line matched OPTION_REGEX. When the target nested section is currently empty (no sub-keys yet — a valid config state, e.g. s3 = immediately followed by another [section], or s3 = as the last line of the file), current_indent (and, in the end-of-file case, the loop variable i) is never assigned, and the subsequent reference raises UnboundLocalError instead of writing the value.

Fix

Initialize current_indent = None and i = index - 1 before the loop. None never equals starting_indent (always an int), so behavior for every previously-passing case (sections with existing sub-keys) is unchanged — this only fixes the two previously-crashing empty-section paths.

Test plan

  • Added test_add_to_empty_nested_stanza_followed_by_section and test_add_to_empty_nested_stanza_at_eof to tests/unit/customizations/configure/test_writer.py.
    • Verified both fail with UnboundLocalError against the pre-fix code, and pass after the fix (including correctly writing the value, not just avoiding the crash).
  • Ran tests/unit/customizations/configure/ (109 passed) and tests/functional/configure/ (33 passed) — no regressions.
  • Added a changelog entry under .changes/next-release/.

🤖 Generated with Claude Code

…mpty nested sections

current_indent (and the loop index i) were only assigned when a
sub-option line matched OPTION_REGEX. Updating a nested section that
currently has no sub-keys (e.g. `s3 =` immediately followed by another
[section] header, or as the last line of the file) left these
variables unbound, raising UnboundLocalError instead of writing the
value.

Initialize current_indent to None and i to the pre-loop index so both
previously-crashing cases insert the new values correctly, matching
the behavior of the equivalent non-empty-section cases.

Fixes aws#10587
@Adityaj0
Adityaj0 requested a review from a team as a code owner August 20, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant