From f45eb3776875ce0ba7434b620d54e8c17d5c8894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Perceval=20Wajsb=C3=BCrt?= Date: Wed, 15 Jan 2025 09:55:15 +0100 Subject: [PATCH] fix: support reference to fields with null values --- changelog.md | 8 ++++++-- confit/config.py | 4 ++-- tests/test_config_instance.py | 11 +++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 85f316c..d131bf4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,11 +1,15 @@ # Changelog +## Unreleased + +- Allow larger than 4096 bytes config files +- Escape tabs and newline when serializing to a config file +- Fix an infinite loop that occured when resolving a reference to a field with a null value + ## v0.7.3 (2024-12-11) - Support interpolated seed in the config file (as a reminder, the seed is treated specifically by confit to initialize random generators **before** any object is resolved) - Support if/else expressions in interpolation, and only resolve the relevant branch -- Allow larger than 4096 bytes config files -- Escape tabs and newline when serializing to a config file ## v0.7.2 (2024-11-23) diff --git a/confit/config.py b/confit/config.py index fccd6f4..0297598 100644 --- a/confit/config.py +++ b/confit/config.py @@ -461,10 +461,10 @@ def rec(obj, loc: Tuple[Union[str, int]] = ()): elif isinstance(obj, tuple): resolved = tuple(rec(v, (*loc, i)) for i, v in enumerate(obj)) elif isinstance(obj, Reference): - resolved = None - while resolved is None: + while True: try: resolved = resolve_reference(obj) + break except (KeyError, NameError): raise MissingReference(obj) else: diff --git a/tests/test_config_instance.py b/tests/test_config_instance.py index 4634f26..a5c4195 100644 --- a/tests/test_config_instance.py +++ b/tests/test_config_instance.py @@ -741,3 +741,14 @@ def test_newline_serialization(): """ ) + + +def test_null_reference(): + config = Config.from_yaml_str( + """ +test: + a: null + b: ${test.a} +""" + ).resolve(registry=registry) + assert config["test"]["b"] is None