Skip to content

Commit

Permalink
Yield None when resolving any value from a None record (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
cariad authored Dec 19, 2023
1 parent af0dc5f commit c099047
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rolumns/data_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def __init__(self, root: Any) -> None:

@staticmethod
def _resolve(parts: List[str], data: Any) -> Iterable[Optional[Any]]:
if data is None:
logger.warning(
"Cannot use %s as indices of None, so yielding None",
parts,
)

yield None
return

if isinstance(data, list):
for d in data:
for r in DataResolver._resolve(parts.copy(), d):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_data_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
@mark.parametrize(
"data, path, expect",
[
(
None,
"name",
[
None,
], # There is no "name" in None.
),
(
{},
"name",
Expand Down

0 comments on commit c099047

Please sign in to comment.