From 44aae79bac0fd3b4415c373f577cee2e14364d22 Mon Sep 17 00:00:00 2001 From: Damien Crier Date: Mon, 8 Jun 2015 17:02:38 +0200 Subject: [PATCH] [FIX] hasattr in controllers returns always 'True' so check error if AttributeError is raised and catch it --- web_warning_on_save/controller.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/web_warning_on_save/controller.py b/web_warning_on_save/controller.py index 9680e33d..12ad2fad 100644 --- a/web_warning_on_save/controller.py +++ b/web_warning_on_save/controller.py @@ -19,9 +19,12 @@ # ############################################################################## +import xmlrpclib + import openerp + class WarningOnSaveController(openerp.addons.web.http.Controller): _cp_path = "/web_warning_on_save" @@ -32,8 +35,12 @@ class WarningOnSaveController(openerp.addons.web.http.Controller): if method does not exist in the model, do nothing """ m = req.session.model(model) - if hasattr(m, 'check_warning_on_save'): + try: return getattr(m, 'check_warning_on_save')(id, req.context) - else: - return False + except xmlrpclib.Fault as e: + if 'AttributeError' in e.faultString: + return False + else: + raise openerp.osv.osv.except_osv('Error', e.faultCode) +