Skip to content

Commit

Permalink
Use duck-typing instead of Mapping for recursive settings updating.
Browse files Browse the repository at this point in the history
  • Loading branch information
wrwrwr committed Jan 7, 2012
1 parent 041da37 commit d11bdc3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions dbindexer/base.py
@@ -1,20 +1,21 @@
from collections import Mapping
from django.conf import settings
from django.utils.importlib import import_module


def merge_dicts(d1, d2):
'''Update dictionary recursively.'''
'''Update dictionary recursively. If values for a given key exist in both dictionaries and are dict-like they are merged.'''

for k, v in d2.iteritems():

# Only merge if the key exists in both dictionaries and both values are dictionary-like.
if k in d1 and isinstance(v, Mapping) and isinstance(d1[k], Mapping):
# Try to merge the values as if they were dicts.
try:
merge_dicts(d1[k], v)

# Otherwise just overwrite the original value (if any).
else:
except (AttributeError, KeyError):
d1[k] = v


class DatabaseOperations(object):
dbindexer_compiler_module = __name__.rsplit('.', 1)[0] + '.compiler'

Expand Down

0 comments on commit d11bdc3

Please sign in to comment.