Fix UnboundLocalError in nested config updates - #10598
Open
krantboy wants to merge 1 commit into
Open
Conversation
_update_subattributes() read ``current_indent`` on every line but only assigned it when OPTION_REGEX matched. Any non-option line directly after a nested key -- a comment, a blank line, or a section header -- was therefore read before assignment and raised UnboundLocalError. ``i`` had the same problem when the nested key was the last line in the file, leaving the for-else branch with no loop variable. Classify each line explicitly rather than carrying the indent of the previous match forward, and seed ``i`` so an empty loop range takes the same append path as running off the end of the file. Appending to a block at the end of a file with no trailing newline joins two lines together, so add the missing newline first. Without this the change above turns a crash into a silently corrupted config file. Fixes aws#10348
krantboy
force-pushed
the
fix-10348-nested-config-unbound
branch
from
August 23, 2026 08:37
a340ff7 to
b1afbc0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10348
ConfigFileWriter._update_subattributes()readscurrent_indenton every linebut only assigns it when
OPTION_REGEXmatches, so any non-option line directlyafter a nested key is read before assignment.
ihas the same problem when thenested key is the last line in the file and the loop body never runs.
All three of these shapes crash on
aws configure set s3.signature_version s3v4:The fix classifies each line explicitly instead of carrying the previous match's
indent forward, and seeds
ibefore the loop. It also adds a missing trailingnewline before appending, without which the above would turn the crash into a
corrupted config file.
Tests cover all three shapes plus an empty nested block with no trailing
newline; each fails before the change.