runtime
400 / 500
question 400 Software Architecture · hard

Review a configuration change

Before a deployment, reviewers want to see exactly which settings change. Write config_diff(old, new) over nested configuration dictionaries: list every leaf setting that was added, removed or changed, as (dotted.key, old_value, new_value) with None for a side where the setting doesn't exist. A dictionary on both sides is compared key by key; anything else (including lists) is a value.

Functionconfig_diff(old, new)
Returnsa list of (key, old_value, new_value) tuples sorted by key; unchanged settings are left out
Keysnested keys joined with dots: db.pool.size; when a dictionary is replaced by a value (or the reverse), report the whole key once
Examples
callconfig_diff({'db': {'host': 'localhost', 'pool': {'size': 5}}, 'debug': True}, {'db': {'host': 'db.internal', 'pool': {'size': 5}}, 'cache': {'ttl': 60}})returns[('cache', None, {'ttl': 60}), ('db.host', 'localhost', 'db.internal'), ('debug', True, None)]
callconfig_diff({'a': 1}, {'a': 1})returns[]
callconfig_diff({'a': 1}, {'a': 2})returns[('a', 1, 2)]

Loading your progress…

Review a configuration change — Python practice · Runtime