Changeset 1182

Show
Ignore:
Timestamp:
03/07/10 08:43:40 (6 months ago)
Author:
gray
Message:

merge_dict_from_to was causing d1 (the from dict) to be modified because it was just assigning the value from d1 to d2, even though the value could be a reference to a deeper structure. so both d1 and d2 would share the same object. the solution is to do a deep copy on the value from d1 before assigning it to d2 so d2 can modify it without d1 being affected.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/flexget/utils/tools.py

    r1181 r1182  
    142142def merge_dict_from_to(d1, d2): 
    143143    """Merges dictionary d1 into dictionary d2. d1 will remain in original form.""" 
     144    import copy 
    144145    for k, v in d1.items(): 
    145146        if k in d2: 
     
    148149                    merge_dict_from_to(d1[k], d2[k]) 
    149150                elif isinstance(v, list): 
    150                     d2[k].extend(v) 
     151                    d2[k].extend(copy.deepcopy(v)) 
    151152                elif isinstance(v, basestring) or isinstance(v, bool) or \ 
    152153                     isinstance(v, int) or isinstance(v, float): 
     
    157158                raise MergeException('Merging key %s failed, conflicting datatypes.' % (k)) 
    158159        else: 
    159             d2[k] = v 
     160            d2[k] = copy.deepcopy(v) 
    160161 
    161162