Skip to content

Commit

Permalink
Fix get_by_path for not existing path
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscoder committed Aug 1, 2019
1 parent 21ca48a commit cf02ff9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion base_fhirpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,16 @@ def get_by_path(data, path, default=None):
if isinstance(key, int):
rv = rv[key]
elif isinstance(key, dict):
matched_index = -1
for index, item in enumerate(rv):
if all([item.get(k, None) == v for k, v in
key.items()]):
rv = rv[index]
matched_index = index
break
if matched_index == -1:
rv = None
else:
rv = rv[matched_index]
else: # pragma: no cover
raise TypeError(
'Can not lookup by {0} in list. '
Expand Down

0 comments on commit cf02ff9

Please sign in to comment.