From 3b6341bf41747e4f2239341545a56d1f4f691238 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 8 Sep 2020 23:01:42 +0200 Subject: [PATCH] flow/transfer: fix pk's not being replaced in lists --- passbook/flows/transfer/importer.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/passbook/flows/transfer/importer.py b/passbook/flows/transfer/importer.py index 5b79084d0..a3239f771 100644 --- a/passbook/flows/transfer/importer.py +++ b/passbook/flows/transfer/importer.py @@ -45,14 +45,20 @@ class FlowImporter: 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""" + 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(): if isinstance(value, (list, dict)): - continue - if value in self.__pk_map: - attrs[key] = self.__pk_map[value] - self.logger.debug( - "updating reference in entry", key=key, new_value=attrs[key] - ) + for idx, _inner_value in enumerate(value): + attrs[key][idx] = updater(_inner_value) + else: + attrs[key] = updater(value) return attrs def __query_from_identifier(self, attrs: Dict[str, Any]) -> Q: