Fix UnboundLocalError in aws configure set for nested values - #10555
Open
Adityaj0 wants to merge 1 commit into
Open
Fix UnboundLocalError in aws configure set for nested values#10555Adityaj0 wants to merge 1 commit into
Adityaj0 wants to merge 1 commit into
Conversation
`ConfigFileWriter._update_subattributes` only assigns `current_indent` inside the `if match is not None:` branch but reads it unconditionally, and reads `i` in the loop's `else:` clause. Both are unbound when the line after the nested key does not parse as an option, or when the loop body never runs at all. This made `aws configure set <section>.<key>.<subkey> <value>` abort with `UnboundLocalError` and exit 255, leaving the config untouched, for three valid config layouts: the nested key followed by a comment, by a blank line, or being the last line of the file. Seed both names before the loop. `None` never compares equal to `starting_indent`, preserving the existing behaviour that a non-option line does not terminate the nested block, and seeding `i` with the nested key's own line appends the values directly after it when nothing follows. Fixes aws#10554 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 task
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.
Issue
Fixes #10554
Description of changes
aws configure set <section>.<key>.<subkey> <value>crashes with an internalUnboundLocalErrorand exit code255when the nested parent key is not immediately followed by another indented option line:In
ConfigFileWriter._update_subattributes,current_indentis only assigned inside theif match is not None:branch, andiis only assigned if theforloop body runs. Both are read unconditionally afterwards:Comments and blank lines do not match
OPTION_REGEX, so if one of those directly follows the parent key,current_indentis never bound. If the parent key is the last line in the file,range()is empty and bothcurrent_indentandiare unbound when theelse:clause runs.Three valid config layouts trigger it — all three parse correctly via
botocore.configloader.raw_config_parse:The fix seeds both names before the loop:
This is behaviour-preserving for every input that previously worked.
current_indentis read only at those two comparison sites, andNonenever compares equal tostarting_indent— which is exactly the "this line does not end the nested block" outcome that a stale-but-different indent already produced for comments appearing later within a block. In theelse:clause the comparison was already unconditionally true whenever it was reached, since an equal indent would have broken out of the loop. Seedingiwith the nested key's own line makes the values get appended directly after it when nothing follows.Resulting output for the three cases above:
Testing
Three regression tests added to
tests/unit/customizations/configure/test_writer.py, one per layout. Each fails withUnboundLocalErroronv2and passes with the fix.tests/unit/customizations/configure/andtests/functional/configure/: 313 passedtests/unit/customizations/: no new failures (the single failure,test_emr_utils.py::TestEMRutils::test_which_with_existing_command, reproduces identically on unmodifiedv2in this environment and is unrelated)aws configure set default.s3.max_concurrent_requests 20now exits0, and thataws configure get default.s3.max_concurrent_requestsreads the value back.Both touched files already fail
ruff format --check/ruff checkon unmodifiedv2, so I deliberately left the surrounding formatting alone rather than growing the diff; the added lines introduce no new findings.