From fcc1858d3e611c841d0aef8c970e2c1b56074b50 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 6 Oct 2018 10:47:56 +0200 Subject: Importer: do not crash on bad default configuration --- ishtar_common/models_imports.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'ishtar_common/models_imports.py') diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index b52219c11..d999f61d2 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -238,9 +238,18 @@ def get_associated_model(parent_model, keys): OBJECT_CLS = import_class(parent_model) else: OBJECT_CLS = parent_model + fields = get_model_fields(OBJECT_CLS) for idx, item in enumerate(keys): if not idx: - field = get_model_fields(OBJECT_CLS)[item] + if item not in fields: + raise ImporterError( + unicode( + _(u"Importer configuration error: " + u"\"{}\" is not available for \"{}\"." + u" Check your default and column " + u"configuration")).format( + item, OBJECT_CLS.__name__)) + field = fields[item] if hasattr(field, 'rel') and hasattr(field.rel, 'to'): model = field.rel.to if type(field) == ModelBase: -- cgit v1.2.3