One function

object_merge in dynaconf/dynaconf

The author described this change as fix: preserve nested dict key order when object_merge merges old into new. It counts as a record because the check below fails on the code as it stood at 332d1f88c and passes on 6e76252f8, with nothing else changed between the two runs.

Fix saved2026-06-25
Sharing licenceMIT · LICENSE
Change size+10 0

What the code was meant to do, written into the code itself as a docstring

Recursively merge two data structures, new is mutated in-place. :param old: The existing data. :param new: The new data to get old values merged in to. :param unique: When set to True existing list items are not set. :param full_path: Indicates the elements of a tree. :param list_merge: Methods to use to merge lists - merge: default merge behavior, i.e. (unique) concatenation - shallow: replace the top-most level list of the nested structure - deep: iteratively traverse the nested structure and replace the element in the list at the level specified by the full_path

The change

9999 full_path=full_path[1:] if full_path else None,
100100 list_merge=list_merge,
101101 )
102+
103+ # Restore old key order: keys that exist in old keep old's
104+ # relative order; keys that are new-only come last.
105+ old_keys = list(safe_items(old))
106+ old_key_set = {k for k, _ in old_keys}
107+ new_only = [k for k in new if k not in old_key_set]
108+ ordered = [k for k, _ in old_keys if k in new] + new_only
109+ for k in ordered:
110+ new[k] = new.pop(k)
111+
102112 handle_metavalues(old, new, list_merge=list_merge)
103113
104114 return new

The check that tells the two apart

failpass·tests/test_utils.py::test_merge_dict_preserves_old_key_order

Check file tests/test_utils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it332d1f88c989b6067cbbe5b1c5706ec2eeedc35f
Broken version dated2026-06-24
Moduledynaconf.utils.__init__
Units changedobject_merge
Fingerprintb54e6516dd4ea820
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in dynaconf/dynaconf