Skip to content

Commit

Permalink
Merge pull request #115 from deepmind/searchvar
Browse files Browse the repository at this point in the history
Fixed bug with searchvar keys chain
  • Loading branch information
adrianchifor authored Jun 6, 2018
2 parents 4d0af60 + d2f9ccc commit 50cdb23
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions kapitan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def flatten_dict(d, parent_key='', sep='.'):
return dict(items)


def deep_get(dictionary, keys):
def deep_get(dictionary, keys, previousKey=None):
'''
Search recursively for 'keys' in 'dictionary' and return value, otherwise return None
'''
Expand All @@ -202,7 +202,7 @@ def deep_get(dictionary, keys):
return None

# Recurse with next keys in the chain on the dict
return deep_get(value, keys[1:])
return deep_get(value, keys[1:], previousKey=keys[0])
else:
if isinstance(dictionary, dict):
# If we find nothing, check for globbing, loop and match with dict keys
Expand All @@ -215,14 +215,20 @@ def deep_get(dictionary, keys):
return dictionary[dict_key]

# If we have more variables in the chain, continue recursion
return deep_get(dictionary[dict_key], keys[1:])

# No globbing, move down the dictionary and recurse
for v in dictionary.values():
if isinstance(v, dict):
item = deep_get(v, keys)
if item:
return item
return deep_get(dictionary[dict_key], keys[1:], previousKey=keys[0])

if not previousKey:
# No previous keys in chain and no globbing, move down the dictionary and recurse
for v in dictionary.values():
if isinstance(v, dict):
item = None
if len(keys) > 1:
item = deep_get(v, keys, previousKey=keys[0])
else:
item = deep_get(v, keys)

if item:
return item

return value

Expand Down

0 comments on commit 50cdb23

Please sign in to comment.