Skip to content

Commit f45eb37

Browse files
committed
fix: support reference to fields with null values
1 parent df6a030 commit f45eb37

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

changelog.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Allow larger than 4096 bytes config files
6+
- Escape tabs and newline when serializing to a config file
7+
- Fix an infinite loop that occured when resolving a reference to a field with a null value
8+
39
## v0.7.3 (2024-12-11)
410

511
- 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)
612
- Support if/else expressions in interpolation, and only resolve the relevant branch
7-
- Allow larger than 4096 bytes config files
8-
- Escape tabs and newline when serializing to a config file
913

1014
## v0.7.2 (2024-11-23)
1115

confit/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,10 @@ def rec(obj, loc: Tuple[Union[str, int]] = ()):
461461
elif isinstance(obj, tuple):
462462
resolved = tuple(rec(v, (*loc, i)) for i, v in enumerate(obj))
463463
elif isinstance(obj, Reference):
464-
resolved = None
465-
while resolved is None:
464+
while True:
466465
try:
467466
resolved = resolve_reference(obj)
467+
break
468468
except (KeyError, NameError):
469469
raise MissingReference(obj)
470470
else:

tests/test_config_instance.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,3 +741,14 @@ def test_newline_serialization():
741741
742742
"""
743743
)
744+
745+
746+
def test_null_reference():
747+
config = Config.from_yaml_str(
748+
"""
749+
test:
750+
a: null
751+
b: ${test.a}
752+
"""
753+
).resolve(registry=registry)
754+
assert config["test"]["b"] is None

0 commit comments

Comments
 (0)