From 41f439adac946e21b71ddfca4ca17ede848ec56d Mon Sep 17 00:00:00 2001 From: Mattijs Ugen <144798+akaIDIOT@users.noreply.github.com> Date: Tue, 25 Nov 2025 11:29:51 +0100 Subject: [PATCH 1/4] Unwrap value to be dumped for _TOMLFormat This mimics the other implementations --- confidence/formats.py | 1 + 1 file changed, 1 insertion(+) diff --git a/confidence/formats.py b/confidence/formats.py index 9e74266..7ecdda8 100644 --- a/confidence/formats.py +++ b/confidence/formats.py @@ -84,6 +84,7 @@ def loads(self, string: str) -> typing.Any: return tomlkit.value(string) def dumps(self, value: typing.Any) -> str: + value = unwrap(value) try: # attempt to dump the value as TOML document return tomlkit.dumps(value) From 5f1c98486f731fb060775ede6de36fc8a5665be8 Mon Sep 17 00:00:00 2001 From: Mattijs Ugen <144798+akaIDIOT@users.noreply.github.com> Date: Tue, 25 Nov 2025 13:19:24 +0100 Subject: [PATCH 2/4] Update tests to expect proper unwrapping of rich values when dumping --- tests/test_formats.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/test_formats.py b/tests/test_formats.py index 8ce8586..661e593 100644 --- a/tests/test_formats.py +++ b/tests/test_formats.py @@ -2,6 +2,7 @@ import pytest +from confidence import Configuration, unwrap from confidence.formats import JSON, TOML, YAML @@ -16,12 +17,22 @@ def test_singular_value_roundtrip(format, value): @pytest.mark.parametrize('format', (JSON, TOML, YAML, YAML(suffix='.conf', encoding='utf-32'))) -@pytest.mark.parametrize('value', ([], {}, [1, 2, 'a'], {'a': 1, 'b': 42.0, 'c': {'d': 'str'}, 'e': [{'g': True}]})) +@pytest.mark.parametrize( + 'value', + ( + [], + {}, + [1, 2, 'a'], + {'a': 1, 'b': 42.0, 'c': {'d': 'str'}, 'e': [{'g': True}]}, + Configuration({'a.b.c': 42}), + Configuration({'a.b': [1, 2, '${a}']}), + ), +) def test_multiple_values_roundtrip(format, value, tmp_path): fname = tmp_path / f'config{format.suffix}' format.dumpf(value, fname) - assert format.loadf(fname) == value + assert format.loadf(fname) == unwrap(value) def test_edit_format(): From 8726a059dc4a6a2d3268fe09907cb2a7736cb3f7 Mon Sep 17 00:00:00 2001 From: Mattijs Ugen <144798+akaIDIOT@users.noreply.github.com> Date: Tue, 25 Nov 2025 13:20:45 +0100 Subject: [PATCH 3/4] Mention change in CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2a796d1..92be4f2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ Changes development (main) ------------------ -- +- Fix dump functions failing to write nested `Configuration` instances in TOML format. 0.17.1 (2025-10-15) ------------------- From 17d15ad1039be901a233571fa5cb5a912cb2b6c9 Mon Sep 17 00:00:00 2001 From: Mattijs Ugen <144798+akaIDIOT@users.noreply.github.com> Date: Tue, 25 Nov 2025 13:28:55 +0100 Subject: [PATCH 4/4] Clarify reasoning behind test Configuration instances --- tests/test_formats.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_formats.py b/tests/test_formats.py index 661e593..cec608e 100644 --- a/tests/test_formats.py +++ b/tests/test_formats.py @@ -24,7 +24,9 @@ def test_singular_value_roundtrip(format, value): {}, [1, 2, 'a'], {'a': 1, 'b': 42.0, 'c': {'d': 'str'}, 'e': [{'g': True}]}, + # nested configuration object should get unwrapped before serialization Configuration({'a.b.c': 42}), + # serialization should not be trying to resolve references, this one would cause a recursion error if it does Configuration({'a.b': [1, 2, '${a}']}), ), )