From 1df1a8c8130e5a9a1bdac736979ba24f02369c40 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 5 Feb 2026 17:19:07 +0100 Subject: 🚑️ imports: fix concatenation of existing fields - fix concat string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/data_importer.py | 50 +++++++++++----------- .../fixtures/initial_importtypes-tests-fr.json | 2 +- 2 files changed, 25 insertions(+), 27 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 7bdade5ab..584917c8e 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1568,7 +1568,7 @@ class Importer(object): field_name = field_name[idx_fields] if type(force_new) in (list, tuple): force_new = force_new[idx_fields] - if formater.concat: + if formater.concat and any(formater.concat): self.concats.add(field_name) concat_str = formater.concat_str if type(formater.concat_str) in (list, tuple): @@ -2141,42 +2141,40 @@ class Importer(object): raise self._get_does_not_exist_in_db_error(cls, dct) dct["defaults"] = defaults.copy() - if not created and not path and self.UNICITY_KEYS: + # manage default values and concatenation + if not created and not path and self.UNICITY_KEYS and obj is not None: updated_dct = {} - if self.conservative_import: - for k in dct["defaults"]: - new_val = dct["defaults"][k] - if new_val is None or new_val == "": - continue - val = getattr(obj, k) - if val is None or val == "": - updated_dct[k] = new_val - elif ( - k in self.concats - and type(val) == str - and type(new_val) == str - ): - updated_dct[k] = val + "\n" + new_val - else: - for k in dct["defaults"]: - new_val = dct["defaults"][k] - if new_val is None or new_val == "": - continue - if obj and k == "data": - updated_dct[k] = update_data(obj.data, new_val) - else: - updated_dct[k] = new_val + for k in dct["defaults"]: + new_val = dct["defaults"][k] + if new_val is None or new_val == "": + continue + val = getattr(obj, k) + if val is None or val == "": + updated_dct[k] = new_val + elif obj and k == "data": + updated_dct[k] = update_data(obj.data, new_val) + elif ( + k in self.concats + and type(val) == str + and type(new_val) == str + ): + sep = "" + if k in self.concat_str: + sep = self.concat_str[k] + updated_dct[k] = val + sep + new_val if updated_dct: if self.simulate: self.updated_objects[-1][-1] = updated_dct else: + obj.__class__.objects.filter(pk=obj.pk).update( + **updated_dct + ) for k in updated_dct: setattr(obj, k, updated_dct[k]) obj._timestamp = self.timestamp obj._queue = "low_priority" if hasattr(obj, "no_post_process"): obj.no_post_process(history=True) - obj.save() if ( not self.simulate and self.import_instance diff --git a/ishtar_common/fixtures/initial_importtypes-tests-fr.json b/ishtar_common/fixtures/initial_importtypes-tests-fr.json index eadf26ff5..f8e000cd3 100644 --- a/ishtar_common/fixtures/initial_importtypes-tests-fr.json +++ b/ishtar_common/fixtures/initial_importtypes-tests-fr.json @@ -2047,7 +2047,7 @@ "mcc-mobilier", 23 ], - "target": "base_finds__description", + "target": "description", "formater_type": [ "UnicodeFormater", "1000", -- cgit v1.2.3