Skip to content

Commit

Permalink
fix issue borgbase#940 - KeyError in get_dict_from_list
Browse files Browse the repository at this point in the history
- cause of error : defaultdict added more defaultdict while attempting to traverse the tree, but once a 'potential leaf' node was added, it was added as a dict, not a defaultdict.
- two possible solutions:
    - 1 - change everywhere that adds a 'potential' leaf node to add a defaultdict (ie nested_dict()) - this occurs in several places, but not many.
    - 2 - change get_dict_from_list to add a default dict (not defaultdict) when traversing the tree, for the case where a multi-level node is added on top of an existing node. This requires only changing a single location, and means that the dictionaries returned by accessing the tree will behave like normal dict (ie, won't by default add missing keys).
  • Loading branch information
Robert Blenis committed Apr 12, 2021
1 parent 518df6f commit c762e04
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/vorta/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import argparse
import errno
import getpass
import operator
import os
import platform
import re
import sys
import unicodedata
from collections import defaultdict
from datetime import datetime as dt
from functools import reduce

Expand Down Expand Up @@ -105,11 +103,11 @@ def nested_dict():
- https://stackoverflow.com/a/16724937/3983708
- https://stackoverflow.com/a/14692747/3983708
"""
return defaultdict(nested_dict)
return dict()


def get_dict_from_list(dataDict, mapList):
return reduce(operator.getitem, mapList, dataDict)
return reduce(lambda d, k: d.setdefault(k, {}), mapList, dataDict)


def choose_file_dialog(parent, title, want_folder=True):
Expand Down

0 comments on commit c762e04

Please sign in to comment.