flow/transfer: fix pk's not being replaced in lists

This commit is contained in:
Jens Langhammer 2020-09-08 23:01:42 +02:00
parent 3b97389833
commit 3b6341bf41
1 changed files with 12 additions and 6 deletions

View File

@ -45,14 +45,20 @@ class FlowImporter:
def __update_pks_for_attrs(self, attrs: Dict[str, Any]) -> Dict[str, Any]: def __update_pks_for_attrs(self, attrs: Dict[str, Any]) -> Dict[str, Any]:
"""Replace any value if it is a known primary key of an other object""" """Replace any value if it is a known primary key of an other object"""
def updater(value) -> Any:
if value in self.__pk_map:
self.logger.debug(
"updating reference in entry", value=value
)
return self.__pk_map[value]
return value
for key, value in attrs.items(): for key, value in attrs.items():
if isinstance(value, (list, dict)): if isinstance(value, (list, dict)):
continue for idx, _inner_value in enumerate(value):
if value in self.__pk_map: attrs[key][idx] = updater(_inner_value)
attrs[key] = self.__pk_map[value] else:
self.logger.debug( attrs[key] = updater(value)
"updating reference in entry", key=key, new_value=attrs[key]
)
return attrs return attrs
def __query_from_identifier(self, attrs: Dict[str, Any]) -> Q: def __query_from_identifier(self, attrs: Dict[str, Any]) -> Q: