Skip to content

Commit

Permalink
Do not modify object tree in filter module «aci2.py»
Browse files Browse the repository at this point in the history
Previously scalar attributes have been deleted after evaluation.
This simplified further processing of lists and dicts.
However, if the object tree uses anchors and aliases, deleting
attributes invalidates the aliases.
  • Loading branch information
velotiger committed Mar 20, 2022
1 parent 1a361b5 commit 09a5d1f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions plugins/filter/aci2.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ def worker(itemList, depth, result, cache, prefix):
for subItem in list(item.keys()):
if not isinstance(item[subItem], (dict, list)):
# Flat key/value pair.
subcache['%s%s' % (prefix, subItem)] = item.pop(subItem)
subcache['%s%s' % (prefix, subItem)] = item[subItem]
# All key/value pairs are evaluated before dicts and lists.
# Otherwise, some attributes might not be transferred from the
# cache to the result list.
# Remaining subItem's are lists or dicts of sub-instances.
if regexList[depth] is not None and (name is None or not regexList[depth].fullmatch(name)):
# If regex was specified and the nameAttr does not match, do
# not follow the path but continue with next item. Also a
Expand All @@ -177,10 +176,13 @@ def finder(objDict, depth=-1, result=[], cache={}, prefix=''):
# Check if object type is in tree at given depth.
if keyList[depth] in objDict:
# Prepare item list. ACI objects may be stored as list or dict.
if isinstance(objDict[keyList[depth]], dict):
if isinstance(objDict[keyList[depth]], list):
itemList = objDict[keyList[depth]]
elif isinstance(objDict[keyList[depth]], dict):
itemList = list(objDict[keyList[depth]].values())
else:
itemList = objDict[keyList[depth]]
# Neither dict nor list – return to upper level.
return result
result = worker(itemList, depth, result, cache.copy(), prefix)
return result

Expand Down

0 comments on commit 09a5d1f

Please sign in to comment.