Skip to content

Pass append_lists through nested merge_dicts calls - #3883

Open
nursnaaz wants to merge 1 commit into
boto:developfrom
nursnaaz:fix/merge-dicts-nested-append-lists
Open

nursnaaz wants to merge 1 commit into
boto:developfrom
nursnaaz:fix/merge-dicts-nested-append-lists

Conversation

@nursnaaz

Copy link
Copy Markdown

botocore.utils.merge_dicts(dict1, dict2, append_lists=True) is documented to append lists instead of replacing them. When the lists sit inside a nested dict, the recursive call did not pass append_lists on, so the second list replaced the first:

merge_dicts({'Foo': {'Bar': [1]}}, {'Foo': {'Bar': [2]}}, append_lists=True)
# before: {'Foo': {'Bar': [2]}}
# after:  {'Foo': {'Bar': [1, 2]}}

The fix passes append_lists=append_lists to the nested call. Behavior without the flag is unchanged.

boto3/resources/collection.py calls merge_dicts with append_lists=True when it clones a collection or builds pages. No shipped resource model nests lists this way today, so the effect is small. It would show up for chained .filter() calls with a list parameter inside a dict.

Tests: test_nested_list_values_append fails without the change and passes with it. test_nested_list_values_no_append pins the existing replace behavior. The full tests/unit suite passes (4664 passed, 102 skipped). ruff check and ruff format --check are clean. A changelog entry is in .changes/next-release/.

Generated by AI tools, and reviewed by Mohamed Noordeen Alaudeen (@nursnaaz).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

merge_dicts documents that dicts can have arbitrary nesting and that
append_lists appends list values instead of replacing them, but the
recursive call for nested dicts dropped the flag, so lists below the
top level were replaced.
@nursnaaz
nursnaaz requested a review from a team as a code owner November 21, 2026 16:27
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.

1 participant