raise dedicated exception when loading existing content fails (#61364)

This commit is contained in:
Frédéric Péters 2022-02-02 17:54:54 +01:00
parent 6690944e54
commit 32224317a0
1 changed files with 18 additions and 1 deletions

View File

@ -49,6 +49,8 @@ class Cmd(Command):
existing_category = Category.get_by_urlname(category.url_name)
except KeyError:
category.store()
except Exception as e:
raise Exception('failed to load existing category %r' % filename) from e
else:
# replace
category.id = existing_category.id
@ -65,6 +67,8 @@ class Cmd(Command):
existing_datasource = NamedDataSource.get_by_slug(datasource.slug, ignore_errors=False)
except KeyError:
datasource.store(comment='Indus Initial Import')
except Exception as e:
raise Exception('failed to load existing datasource %r' % filename) from e
else:
# replace
datasource.id = existing_datasource.id
@ -77,7 +81,10 @@ class Cmd(Command):
mail_template = MailTemplate.import_from_xml(
open(os.path.join(self.directory, 'mail-templates', filename))
)
existing_mail_template = MailTemplate.get_by_slug(mail_template.slug)
try:
existing_mail_template = MailTemplate.get_by_slug(mail_template.slug)
except Exception as e:
raise Exception('failed to load existing mail template %r' % filename) from e
if existing_mail_template is None:
mail_template.store()
else:
@ -100,6 +107,8 @@ class Cmd(Command):
][0]
except IndexError:
workflow.store(comment='Indus Initial Import')
except Exception as e:
raise Exception('failed to load existing workflow %r' % filename) from e
else:
# replace
workflow.id = existing_workflow.id
@ -114,6 +123,8 @@ class Cmd(Command):
existing_wscall = NamedWsCall.get(filename, ignore_errors=False)
except KeyError:
wscall.store(comment='Indus Initial Import')
except Exception as e:
raise Exception('failed to load existing wscall %r' % filename) from e
else:
# replace
wscall.id = existing_wscall.id
@ -131,6 +142,8 @@ class Cmd(Command):
existing_blockdef = BlockDef.get_on_index(blockdef.slug, 'slug')
except KeyError:
blockdef.store(comment='Indus Initial Import')
except Exception as e:
raise Exception('failed to load existing block %r' % filename) from e
else:
# replace
blockdef.id = existing_blockdef.id
@ -148,6 +161,8 @@ class Cmd(Command):
existing_carddef = CardDef.get_by_urlname(carddef.url_name)
except KeyError:
carddef.store(comment='Indus Initial Import')
except Exception as e:
raise Exception('failed to load existing carddef %r' % filename) from e
else:
# replace
carddef.id = existing_carddef.id
@ -165,6 +180,8 @@ class Cmd(Command):
existing_formdef = FormDef.get_by_urlname(formdef.url_name)
except KeyError:
formdef.store(comment='Indus Initial Import')
except Exception as e:
raise Exception('failed to load existing formdef %r' % filename) from e
else:
# partial update
for attribute in (