Skip to content

Commit

Permalink
[FIX] mail: better mail template user error
Browse files Browse the repository at this point in the history
To reproduce:
Introduce some error in a mail template.
For instance:
`% set bug = object.not_exiting_function()`

Before this commit:
The user message is confusing with irrelevant information.
In my example case:
```
Failed to render template <Template memory:7f76f424b2b0> using values {'format_date': <function MailTemplate.render_template.<locals>.<lambda> at 0x7f76e9422d08>, 'format_tz': <function MailTemplate.render_template.<locals>.<lambda> at 0x7f76e9422840>, 'format_amount': <function MailTemplate.render_template.<locals>.<lambda> at 0x7f76e9422950>, 'user': res.users(1,), 'ctx': {'lang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 1, 'type': 'out_invoice', 'journal_type': 'sale', 'params': {'action': 198}, 'active_model': 'account.invoice', 'active_id': 3, 'active_ids': [3], 'default_model': 'account.invoice', 'default_res_id': 3, 'default_use_template': True, 'default_template_id': 7, 'default_composition_mode': 'comment', 'mark_invoice_as_sent': True, 'custom_layout': 'account.mail_template_data_notification_email_account_invoice', 'force_email': True, 'search_disable_custom_filters': True, 'tpl_partners_only': True, 'safe': False}, 'object': account.invoice(3,)}
```

After this commit:
More relevant information are added to the logs and user message.
In my example case:
`UndefinedError: 'odoo.api.account.invoice object' has no attribute 'not_exiting_function'`

OPW-2266567

closes odoo#52417

X-original-commit: 6ae9c09
Signed-off-by: Richard Mathot (rim) <rim@openerp.com>
  • Loading branch information
lse-odoo committed Jun 4, 2020
1 parent d515e42 commit 711d1a8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions addons/mail/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,10 @@ def _render_template(self, template_txt, model, res_ids, post_process=False):
variables['object'] = record
try:
render_result = template.render(variables)
except Exception:
except Exception as e:
_logger.info("Failed to render template %r using values %r" % (template, variables), exc_info=True)
raise UserError(_("Failed to render template %r using values %r")% (template, variables))
raise UserError(_("Failed to render template %r using values %r") % (template, variables) +
"\n\n%s: %s" % (type(e).__name__, str(e)))
if render_result == u"False":
render_result = u""
results[res_id] = render_result
Expand Down

0 comments on commit 711d1a8

Please sign in to comment.