Allow suppression of warnings when removing duplicate key values
i.e. an importer can invoke this method with `warn=False` (within the `normalize_host_data()` method) to remove duplicates ahead of time; whereas normal importer logic will still remove duplicates but would include the warnings
This commit is contained in:
parent
821624fb01
commit
7372a9b7ff
|
@ -255,7 +255,7 @@ class Importer(object):
|
||||||
factory = factory or self.progress
|
factory = factory or self.progress
|
||||||
return progress_loop(func, items, factory, **kwargs)
|
return progress_loop(func, items, factory, **kwargs)
|
||||||
|
|
||||||
def unique_data(self, host_data):
|
def unique_data(self, host_data, warn=True):
|
||||||
# Prune duplicate keys from host/source data. This is for the sake of
|
# Prune duplicate keys from host/source data. This is for the sake of
|
||||||
# sanity since duplicates typically lead to a ping-pong effect, where a
|
# sanity since duplicates typically lead to a ping-pong effect, where a
|
||||||
# "clean" (change-less) import is impossible.
|
# "clean" (change-less) import is impossible.
|
||||||
|
@ -263,8 +263,9 @@ class Importer(object):
|
||||||
for data in host_data:
|
for data in host_data:
|
||||||
key = self.get_key(data)
|
key = self.get_key(data)
|
||||||
if key in unique:
|
if key in unique:
|
||||||
log.warning("duplicate records detected from {} for key: {}".format(
|
logger = log.warning if warn else log.debug
|
||||||
self.host_system_title, key))
|
logger("duplicate records detected from %s for key: %s",
|
||||||
|
self.host_system_title, key)
|
||||||
else:
|
else:
|
||||||
unique[key] = data
|
unique[key] = data
|
||||||
return list(unique.values()), unique
|
return list(unique.values()), unique
|
||||||
|
|
Loading…
Reference in a new issue