One function

_get_data_by_key in dynaconf/dynaconf

The author described this change as fix(inspect): Fixed an error that would raise when using get_history() with lazy values (#1184). It counts as a record because the check below fails on the code as it stood at 285c4f958 and passes on b23dac456, with nothing else changed between the two runs.

Fix saved2024-10-04
Sharing licenceMIT · LICENSE
Change size+8 2

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

Returns value found in data[key] using dot-path str (e.g, "path.to.key"). Raises KeyError if not found

The change

1414 if sep in key_dotted_path:
1515 key_dotted_path = key_dotted_path.replace(sep, ".")
1616
17+ def handle_repr(value):
18+ # lazy values shouldnt be evaluated for inspecting
19+ if isinstance(value, Lazy):
20+ return value._dynaconf_encode()
21+ return value
22+
1723 def traverse_data(data, path):
1824 # transform `a.b.c` in successive calls to `data['a']['b']['c']`
1925 path = path.split(".")
2026 root_key, nested_keys = path[0], path[1:]
21- result = data[root_key]
27+ result = data._safe_get(root_key)
2228 for key in nested_keys:
23- result = result[key]
29+ result = handle_repr(result._safe_get(key))
2430 return result
2531
2632 try:

The check that tells the two apart

failpass·tests/test_inspect.py::tests_get_history_with_variable_interpolation

Check file tests/test_inspect.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 it285c4f958d4ca16541a66791857cdf6ccaa9962f
Broken version dated2024-08-09
Moduledynaconf.utils.inspect
Units changed_get_data_by_key
Fingerprint5cc5a2688dd86ab8
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