diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-06-20 18:49:32 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-06-20 18:49:32 +0200 |
commit | a1d50ac763064d4c820aa1a97a3711434ffdcc11 (patch) | |
tree | dad065b46a061f9a5101f43221a9504835d3c67e | |
parent | d8dbe942763ca621a6ae91ecfe70d1cd749e793f (diff) | |
download | Ishtar-a1d50ac763064d4c820aa1a97a3711434ffdcc11.tar.bz2 Ishtar-a1d50ac763064d4c820aa1a97a3711434ffdcc11.zip |
Imports: explicit message (instead of crash) on misconfiguration of importers
-rw-r--r-- | ishtar_common/data_importer.py | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 10957e74d..e11e72449 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1400,20 +1400,35 @@ class Importer(object): # get all related fields new_created = {} - for attribute in list(data.keys()): - c_c_path = c_path[:] - if not attribute: - data.pop(attribute) - continue - if not data[attribute]: - field_object, model, direct, m2m = \ - cls._meta.get_field_by_name(attribute) - if m2m: + try: + for attribute in list(data.keys()): + c_c_path = c_path[:] + if not attribute: data.pop(attribute) - continue - if attribute != '__force_new': - self.get_field(cls, attribute, data, m2ms, c_c_path, - new_created) + continue + if not data[attribute]: + field_object, model, direct, m2m = \ + cls._meta.get_field_by_name(attribute) + if m2m: + data.pop(attribute) + continue + if attribute != '__force_new': + self.get_field(cls, attribute, data, m2ms, c_c_path, + new_created) + except (ValueError, IntegrityError) as e: + message = e.message + try: + message = e.message.decode('utf-8') + except (UnicodeDecodeError, UnicodeDecodeError): + message = '' + try: + data = unicode(data) + except UnicodeDecodeError: + data = '' + raise ImporterError( + "Erreur d'import %s %s, contexte : %s, erreur : %s" + % (unicode(cls), unicode("__".join(path)), + unicode(data), message)) create_dict = copy.deepcopy(data) for k in create_dict.keys(): |