Skip to content

Commit

Permalink
fix: support reference to fields with null values
Browse files Browse the repository at this point in the history
  • Loading branch information
percevalw committed Jan 15, 2025
1 parent df6a030 commit f45eb37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 6 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 2 additions & 2 deletions confit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_config_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f45eb37

Please sign in to comment.