Skip to content

fix: avoid mutating summarize_args list in summarize()#10132

Closed
norus wants to merge 1 commit intoaws:developfrom
norus:fix/summarize-arg-mutation
Closed

fix: avoid mutating summarize_args list in summarize()#10132
norus wants to merge 1 commit intoaws:developfrom
norus:fix/summarize-arg-mutation

Conversation

@norus
Copy link

@norus norus commented Mar 14, 2026

Summary

Fix a list mutation bug in scripts/performance/benchmark_utils.py.

Closes #10121

Problem

summarize() called .extend() on the shared summarize_args list before the second subprocess.check_call(). This mutates the list in-place, making the function non-idempotent: any repeated call accumulates duplicate --output-format json flags.

# Before (buggy)
with open(os.path.join(summary_dir, 'summary.json'), 'wb') as f:
    summarize_args.extend(['--output-format', 'json'])  # mutates original
    subprocess.check_call(summarize_args, stdout=f)

Fix

Construct a new list for the JSON invocation, leaving the original untouched.

# After
with open(os.path.join(summary_dir, 'summary.json'), 'wb') as f:
    json_args = summarize_args + ['--output-format', 'json']
    subprocess.check_call(json_args, stdout=f)

Testing

Verified locally that summarize_args is not mutated after the call, and the JSON summary subprocess receives exactly the expected arguments.

The summarize() function was calling .extend() on summarize_args in-place
before the second subprocess.check_call(). This mutates the original list,
making the function non-idempotent: repeated calls accumulate duplicate
--output-format flags.

Construct a new list for the JSON invocation instead.

Fixes aws#10121
@norus
Copy link
Author

norus commented Mar 14, 2026

Closing as duplicate of #10127 which was opened first with the same fix.

@norus norus closed this Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

summarize() Mutates Argument List Between Calls

1 participant