From 2dfd7d5e924a3eac9d1233186f3c565199e67f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 24 Jul 2008 18:40:22 +0200 Subject: [PATCH] Set IntegrityError as UserError --- trytond/osv/osv.py | 14 +++++++++++++- trytond/report/report.py | 7 +++++++ trytond/sql_db.py | 1 + trytond/wizard/wizard.py | 9 ++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/trytond/osv/osv.py b/trytond/osv/osv.py index d717ab5f41..f93c667afb 100644 --- a/trytond/osv/osv.py +++ b/trytond/osv/osv.py @@ -6,7 +6,7 @@ from trytond.netsvc import Service, LocalService, Logger, LOG_ERROR from trytond import pooler import copy import sys -from psycopg2 import IntegrityError +from trytond.sql_db import IntegrityError from trytond.tools import UpdateableDict import traceback from trytond.tools import Cache @@ -50,11 +50,17 @@ class OSVService(Service): 'ConcurrencyException') \ and not CONFIG['verbose']: raise + if isinstance(exception, IntegrityError) and not CONFIG['verbose']: + raise Exception('UserError', 'Constraint Error', + *exception.args) tb_s = reduce(lambda x, y: x+y, traceback.format_exception(*sys.exc_info())) logger = Logger() logger.notify_channel("web-services", LOG_ERROR, 'Exception in call: \n' + tb_s) + if isinstance(exception, IntegrityError): + raise Exception('UserError', 'Constraint Error', + *exception.args) raise def execute(self, dbname, user, object_name, method, *args, **kargs): @@ -83,11 +89,17 @@ class OSVService(Service): 'ConcurrencyException') \ and not CONFIG['verbose']: raise + if isinstance(exception, IntegrityError) and not CONFIG['verbose']: + raise Exception('UserError', 'Constraint Error', + *exception.args) tb_s = reduce(lambda x, y: x+y, traceback.format_exception(*sys.exc_info())) logger = Logger() logger.notify_channel("web-services", LOG_ERROR, 'Exception in call: \n' + tb_s) + if isinstance(exception, IntegrityError): + raise Exception('UserError', 'Constraint Error', + *exception.args) raise return True diff --git a/trytond/report/report.py b/trytond/report/report.py index 495e6ded6f..dce3b97de7 100644 --- a/trytond/report/report.py +++ b/trytond/report/report.py @@ -25,6 +25,7 @@ import tempfile from genshi.filters import Translator import traceback from trytond.config import CONFIG +from trytond.sql_db import IntegrityError MODULE_LIST = [] MODULE_CLASS_LIST = {} @@ -193,10 +194,16 @@ class ReportService(Service): 'ConcurrencyException') \ and not CONFIG['verbose']: raise + if isinstance(exception, IntegrityError) and not CONFIG['verbose']: + raise Exception('UserError', 'Constraint Error', + *exception.args) tb_s = reduce(lambda x, y: x+y, traceback.format_exception(*sys.exc_info())) Logger().notify_channel("web-services", LOG_ERROR, 'Exception in call: ' + tb_s) + if isinstance(exception, IntegrityError): + raise Exception('UserError', 'Constraint Error', + *exception.args) raise def execute(self, dbname, user, report_name, ids, datas, context=None): diff --git a/trytond/sql_db.py b/trytond/sql_db.py index e8ee5cfa73..ddf51e79f5 100644 --- a/trytond/sql_db.py +++ b/trytond/sql_db.py @@ -1,6 +1,7 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. from psycopg2.pool import ThreadedConnectionPool from psycopg2.extensions import ISOLATION_LEVEL_SERIALIZABLE, cursor +from psycopg2 import IntegrityError import psycopg2 import re import os diff --git a/trytond/wizard/wizard.py b/trytond/wizard/wizard.py index 7319fc0859..ad9dd63909 100644 --- a/trytond/wizard/wizard.py +++ b/trytond/wizard/wizard.py @@ -7,6 +7,8 @@ from xml import dom from trytond.osv import OSV from trytond.config import CONFIG import sys +from trytond.sql_db import IntegrityError +import traceback MODULE_LIST = [] MODULE_CLASS_LIST = {} @@ -37,11 +39,16 @@ class WizardService(Service): 'ConcurrencyException') \ and not CONFIG['verbose']: raise - import traceback + if isinstance(exception, IntegrityError) and not CONFIG['verbose']: + raise Exception('UserError', 'Constraint Error', + *exception.args) tb_s = reduce(lambda x, y: x+y, traceback.format_exception(*sys.exc_info())) Logger().notify_channel("web-services", LOG_ERROR, 'Exception in call: ' + tb_s) + if isinstance(exception, IntegrityError): + raise Exception('UserError', 'Constraint Error', + *exception.args) raise def execute(self, dbname, user, wizard_name, data, state='init',