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:
Lance Edgar 2022-05-24 18:39:22 -05:00
parent 821624fb01
commit 7372a9b7ff

View file

@ -255,7 +255,7 @@ class Importer(object):
factory = factory or self.progress
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
# sanity since duplicates typically lead to a ping-pong effect, where a
# "clean" (change-less) import is impossible.
@ -263,8 +263,9 @@ class Importer(object):
for data in host_data:
key = self.get_key(data)
if key in unique:
log.warning("duplicate records detected from {} for key: {}".format(
self.host_system_title, key))
logger = log.warning if warn else log.debug
logger("duplicate records detected from %s for key: %s",
self.host_system_title, key)
else:
unique[key] = data
return list(unique.values()), unique