summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorJulien Castiaux <juc@odoo.com>2020-02-19 13:34:27 +0000
committerRaphael Collet <rco@odoo.com>2020-04-08 08:41:17 +0000
commitab4000fb3cf8fa54ba714ceceec391b78d73755e (patch)
treeb28702ae04a1ce3628f9c6a3ffbd4a9c95324d4d /odoo
parent640e63e371a511c0d6786154408c6f5704077947 (diff)
[REF] base: Remove deprecated exceptions and osv
TL;DR: remember `osv` and `except_orm` ? You can forget about them. * Deprecated `except_orm` dropped. * `UserError` elevated as super type of all user-related errors. * Unused `DeferredException` dropped. * Unused `QWebException` dropped (real one is in `qweb.py`). * `MailDeliveryException` made a python exception. * `name` legacy exception attribute made an alias of the python standard `args[0]` attribute and deprecated. * `value` legacy exception attribute dropped. * `exception_type` RPC error response key dropped. * Deprecated `osv` module dropped. * `--osv-memory-age-limit` cli option made an alias of `--transient-age-limit` and deprecated. The `odoo.exceptions.Warning` have long been a deprecated alias to `UserError`. It is going to be removed in a future version but first we explicitly deprecate it with a warning. The `odoo.exceptions.DeferredException` was a very old internal exception, it has been removed without deprecation notice as it is never raised. The `odoo.exceptions.except_orm` has been a deprecated exception type with deprecation warning for 5 years, it has been removed in favor of UserError which becomes the super class of all user-related errors. The `odoo.base.models.ir_mail_server.MailDeliveryException` was inheriting `except_orm`. As it is not related to a user error but is more of a problem an admin much take care of, the exception has been made a Python error. The `exception_type` JSON key in RPC error responses was holding an hardcoded value derived from the exception type. Its usage has been dropped in favor of the `name` JSON key that holds the precise exception name. Again as it was hardly used in the source code (beside the crash manager) it has been dropped without deprecation warning. Since we are here trying to clean odoo custom exceptions, we are also deprecating the `name` exception attribute in favor of the more standard `args[0]` attribute. The `name` (along with `value`) were two attributes used to raise `except_orm` exceptions before the introduction of `UserError`, `AccessError` and related exceptions. The `name` attribute, at the time, was holding the exception type/title. Nowadays it contains the error message. The `value` attribute, at the time, was holding the error message. Nowadays it is no more used. The `osv` module contains very old deprecated aliases. There is no simple way to log a deprecation warning for osv, osv_memory and osv_abstract but as they have not been in use for ages, they have been removed too. To be consistent, the `--osv-memory-age-limit` cli option has been made a deprecated alias to the `--transient-age-limit`. closes odoo/odoo#45723 Task: 2187728 Related: odoo/enterprise#9162 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo')
-rw-r--r--odoo/addons/base/models/ir_actions.py1
-rw-r--r--odoo/addons/base/models/ir_mail_server.py7
-rw-r--r--odoo/addons/base/tests/test_ir_filters.py4
-rw-r--r--odoo/addons/base/tests/test_res_config.py2
-rw-r--r--odoo/addons/test_exceptions/models.py21
-rw-r--r--odoo/addons/test_exceptions/view.xml24
-rw-r--r--odoo/addons/test_new_api/tests/test_new_fields.py2
-rw-r--r--odoo/exceptions.py100
-rw-r--r--odoo/http.py29
-rw-r--r--odoo/models.py2
-rw-r--r--odoo/osv/__init__.py1
-rw-r--r--odoo/osv/osv.py14
-rw-r--r--odoo/service/model.py10
-rw-r--r--odoo/service/wsgi_server.py26
-rw-r--r--odoo/tools/config.py27
-rw-r--r--odoo/tools/safe_eval.py10
-rw-r--r--odoo/tools/test-config-values-00.conf2
-rw-r--r--odoo/tools/test_config.py12
18 files changed, 91 insertions, 203 deletions
diff --git a/odoo/addons/base/models/ir_actions.py b/odoo/addons/base/models/ir_actions.py
index a3c7c4857ca..5d207e80591 100644
--- a/odoo/addons/base/models/ir_actions.py
+++ b/odoo/addons/base/models/ir_actions.py
@@ -508,6 +508,7 @@ class IrActionsServer(models.Model):
'model': model,
# Exceptions
'Warning': odoo.exceptions.Warning,
+ 'UserError': odoo.exceptions.UserError,
# record
'record': record,
'records': records,
diff --git a/odoo/addons/base/models/ir_mail_server.py b/odoo/addons/base/models/ir_mail_server.py
index 8c5399236c7..8d0bf2a21f1 100644
--- a/odoo/addons/base/models/ir_mail_server.py
+++ b/odoo/addons/base/models/ir_mail_server.py
@@ -15,7 +15,7 @@ import threading
import html2text
from odoo import api, fields, models, tools, _
-from odoo.exceptions import except_orm, UserError
+from odoo.exceptions import UserError
from odoo.tools import ustr, pycompat
_logger = logging.getLogger(__name__)
@@ -24,10 +24,9 @@ _test_logger = logging.getLogger('odoo.tests')
SMTP_TIMEOUT = 60
-class MailDeliveryException(except_orm):
+class MailDeliveryException(Exception):
"""Specific exception subclass for mail delivery errors"""
- def __init__(self, name, value):
- super(MailDeliveryException, self).__init__(name, value)
+
# Python 3: patch SMTP's internal printer/debugger
def _print_debug(self, *args):
diff --git a/odoo/addons/base/tests/test_ir_filters.py b/odoo/addons/base/tests/test_ir_filters.py
index cb4b39ff8e2..59c4a39c608 100644
--- a/odoo/addons/base/tests/test_ir_filters.py
+++ b/odoo/addons/base/tests/test_ir_filters.py
@@ -222,7 +222,7 @@ class TestGlobalDefaults(FiltersCase):
)
Filters = self.env['ir.filters'].with_user(self.USER_ID)
- with self.assertRaises(exceptions.Warning):
+ with self.assertRaises(exceptions.UserError):
Filters.create_or_replace({
'name': 'c',
'model_id': 'ir.filters',
@@ -242,7 +242,7 @@ class TestGlobalDefaults(FiltersCase):
)
Filters = self.env['ir.filters'].with_user(self.USER_ID)
- with self.assertRaises(exceptions.Warning):
+ with self.assertRaises(exceptions.UserError):
Filters.create_or_replace({
'name': 'a',
'model_id': 'ir.filters',
diff --git a/odoo/addons/base/tests/test_res_config.py b/odoo/addons/base/tests/test_res_config.py
index 70d1aed99b8..552d8759715 100644
--- a/odoo/addons/base/tests/test_res_config.py
+++ b/odoo/addons/base/tests/test_res_config.py
@@ -78,7 +78,7 @@ class TestResConfig(TransactionCase):
res = self.ResConfig.get_config_warning(self.error_msg_wo_menu)
# Check type
- self.assertIsInstance(res, exceptions.Warning)
+ self.assertIsInstance(res, exceptions.UserError)
# Check returned value
self.assertEqual(res.args[0], self.expected_final_error_msg_wo_menu)
diff --git a/odoo/addons/test_exceptions/models.py b/odoo/addons/test_exceptions/models.py
index 7028ddda128..cb218aaac32 100644
--- a/odoo/addons/test_exceptions/models.py
+++ b/odoo/addons/test_exceptions/models.py
@@ -2,7 +2,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import odoo.exceptions
-import odoo.osv.osv
from odoo import models, api
from odoo.tools.safe_eval import safe_eval
@@ -14,17 +13,6 @@ class m(models.Model):
_name = 'test.exceptions.model'
_description = 'Test Exception Model'
- def generate_except_osv(self):
- # title is ignored in the new (6.1) exceptions
- raise odoo.osv.osv.except_osv('title', 'description')
-
- def generate_except_orm(self):
- # title is ignored in the new (6.1) exceptions
- raise odoo.exceptions.except_orm('title', 'description')
-
- def generate_warning(self):
- raise odoo.exceptions.Warning('description')
-
def generate_redirect_warning(self):
action = self.env.ref('test_exceptions.action_test_exceptions')
raise odoo.exceptions.RedirectWarning('description', action.id, 'Go to the redirection')
@@ -50,15 +38,6 @@ class m(models.Model):
def generate_validation_error(self):
raise odoo.exceptions.ValidationError('description')
- def generate_except_osv_safe_eval(self):
- self.generate_safe_eval(self.generate_except_osv)
-
- def generate_except_orm_safe_eval(self):
- self.generate_safe_eval(self.generate_except_orm)
-
- def generate_warning_safe_eval(self):
- self.generate_safe_eval(self.generate_warning)
-
def generate_redirect_warning_safe_eval(self):
self.generate_safe_eval(self.generate_redirect_warning)
diff --git a/odoo/addons/test_exceptions/view.xml b/odoo/addons/test_exceptions/view.xml
index 0e8f96a7c91..30f19e19b58 100644
--- a/odoo/addons/test_exceptions/view.xml
+++ b/odoo/addons/test_exceptions/view.xml
@@ -11,18 +11,6 @@
<separator/>
<group>
<div>
- <button name="generate_except_osv" string="except_osv" type="object" icon="fa-refresh text-primary" />
- <label for="generate_except_osv" string="Warning-description"/>
- </div>
- <div>
- <button name="generate_except_orm" string="except_orm" type="object" icon="fa-refresh text-primary"/>
- <label for="generate_except_orm" string="Warning-description"/>
- </div>
- <div>
- <button name="generate_warning" string="Warning" type="object" icon="fa-refresh text-primary"/>
- <label for="generate_warning" string="Warning-description"/>
- </div>
- <div>
<button name="generate_redirect_warning" string="RedirectWarning" type="object" icon="fa-refresh text-primary"/>
<label for="generate_redirect_warning" string="Warning-description-redirection button"/>
</div>
@@ -56,18 +44,6 @@
</div>
<div>
- <button name="generate_except_osv_safe_eval" string="except_osv*" type="object" icon="fa-refresh text-primary"/>
- <label for="generate_except_osv_safe_eval" string="Warning-description"/>
- </div>
- <div>
- <button name="generate_except_orm_safe_eval" string="except_orm*" type="object" icon="fa-refresh text-primary"/>
- <label for="generate_except_orm_safe_eval" string="Warning-description"/>
- </div>
- <div>
- <button name="generate_warning_safe_eval" string="Warning*" type="object" icon="fa-refresh text-primary"/>
- <label for="generate_warning_safe_eval" string="Warning-description"/>
- </div>
- <div>
<button name="generate_redirect_warning_safe_eval" string="RedirectWarning*" type="object" icon="fa-refresh text-primary"/>
<label for="generate_redirect_warning_safe_eval" string="Warning-description-redirection button" class="oe_inline"/>
</div>
diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py
index 97d1cb2dacc..9f895ba5732 100644
--- a/odoo/addons/test_new_api/tests/test_new_fields.py
+++ b/odoo/addons/test_new_api/tests/test_new_fields.py
@@ -1539,7 +1539,7 @@ class TestFields(TransactionCaseWithUserDemo):
'name': 'Test without attachment',
'image_wo_attachment': SVG.decode("utf-8"),
})
- self.assertEqual(e.exception.name, 'Only admins can upload SVG files.')
+ self.assertEqual(e.exception.args[0], 'Only admins can upload SVG files.')
def test_90_binary_svg(self):
from odoo.addons.base.tests.test_mimetypes import SVG
diff --git a/odoo/exceptions.py b/odoo/exceptions.py
index 93a0a84e20f..8400194e75a 100644
--- a/odoo/exceptions.py
+++ b/odoo/exceptions.py
@@ -13,58 +13,64 @@ treated as a 'Server error'.
"""
import logging
-from inspect import currentframe
-from .tools.func import frame_codeinfo
+import warnings
_logger = logging.getLogger(__name__)
-# kept for backward compatibility
-class except_orm(Exception):
- def __init__(self, name, value=None):
- if type(self) == except_orm:
- caller = frame_codeinfo(currentframe(), 1)
- _logger.warning('except_orm is deprecated. Please use specific exceptions like UserError or AccessError. Caller: %s:%s', *caller)
- self.name = name
- self.value = value
- self.args = (name, value)
-
- def __str__(self):
- if not self.value:
- return str(self.name)
- else:
- return super().__str__()
-
-
-class UserError(except_orm):
+class UserError(Exception):
"""Generic error managed by the client.
Typically when the user tries to do something that has no sense given the current
- state of a record.
+ state of a record. Semantically comparable to the generic 400 HTTP status codes.
"""
- def __init__(self, msg):
- super(UserError, self).__init__(msg, value='')
+
+ def __init__(self, message):
+ """
+ :param message: exception message and frontend modal content
+ """
+ super().__init__(message)
+
+ @property
+ def name(self):
+ warnings.warn(
+ "UserError attribute 'name' is a deprecated alias to args[0]",
+ DeprecationWarning)
+ return self.args[0]
# deprecated due to collision with builtins, kept for compatibility
-Warning = UserError
+class Warning(UserError):
+ def __init__(self, *args, **kwargs):
+ warnings.warn(
+ "Warning is a deprecated alias to UserError and is going to be "
+ "removed in a future version.",
+ DeprecationWarning)
+ super().__init__(*args, **kwargs)
class RedirectWarning(Exception):
""" Warning with a possibility to redirect the user instead of simply
displaying the warning message.
+ :param str message: exception message and frontend modal content
:param int action_id: id of the action where to perform the redirection
:param str button_text: text to put on the button that will trigger
the redirection.
"""
- # using this RedirectWarning won't crash if used as an except_orm
+ def __init__(self, message, action, button_text):
+ super().__init__(message, action, button_text)
+
+ # using this RedirectWarning won't crash if used as an UserError
@property
def name(self):
+ warnings.warn(
+ "RedirectWarning attribute 'name' is a deprecated alias to args[0]",
+ DeprecationWarning)
return self.args[0]
-class AccessDenied(Exception):
+class AccessDenied(UserError):
"""Login/password error.
.. note::
@@ -76,14 +82,14 @@ class AccessDenied(Exception):
When you try to log with a wrong password.
"""
- def __init__(self, message='Access denied'):
- super(AccessDenied, self).__init__(message)
+ def __init__(self, message="Access Denied"):
+ super().__init__(message)
self.with_traceback(None)
self.__cause__ = None
self.traceback = ('', '', '')
-class AccessError(except_orm):
+class AccessError(UserError):
"""Access rights error.
.. admonition:: Example
@@ -91,11 +97,8 @@ class AccessError(except_orm):
When you try to read a record that you are not allowed to.
"""
- def __init__(self, msg):
- super(AccessError, self).__init__(msg)
-
-class CacheMiss(except_orm, KeyError):
+class CacheMiss(KeyError):
"""Missing value(s) in cache.
.. admonition:: Example
@@ -104,10 +107,10 @@ class CacheMiss(except_orm, KeyError):
"""
def __init__(self, record, field):
- super(CacheMiss, self).__init__("%r.%s" % (record, field.name))
+ super().__init__("%r.%s" % (record, field.name))
-class MissingError(except_orm):
+class MissingError(UserError):
"""Missing record(s).
.. admonition:: Example
@@ -115,36 +118,11 @@ class MissingError(except_orm):
When you try to write on a deleted record.
"""
- def __init__(self, msg):
- super(MissingError, self).__init__(msg)
-
-class ValidationError(except_orm):
+class ValidationError(UserError):
"""Violation of python constraints.
.. admonition:: Example
When you try to create a new user with a login which already exist in the db.
"""
-
- def __init__(self, msg):
- super(ValidationError, self).__init__(msg)
-
-
-class DeferredException(Exception):
- """ Exception object holding a traceback for asynchronous reporting.
-
- Some RPC calls (database creation and report generation) happen with
- an initial request followed by multiple, polling requests. This class
- is used to store the possible exception occuring in the thread serving
- the first request, and is then sent to a polling request.
-
- ('Traceback' is misleading, this is really a exc_info() triple.)
- """
- def __init__(self, msg, tb):
- self.message = msg
- self.traceback = tb
-
-
-class QWebException(Exception):
- pass
diff --git a/odoo/http.py b/odoo/http.py
index 085eaa29240..2b3472ddc9d 100644
--- a/odoo/http.py
+++ b/odoo/http.py
@@ -106,9 +106,8 @@ def replace_request_password(args):
# don't trigger debugger for those exceptions, they carry user-facing warnings
# and indications, they're not necessarily indicative of anything being
# *broken*
-NO_POSTMORTEM = (odoo.exceptions.except_orm,
- odoo.exceptions.AccessDenied,
- odoo.exceptions.Warning,
+NO_POSTMORTEM = (odoo.exceptions.AccessDenied,
+ odoo.exceptions.UserError,
odoo.exceptions.RedirectWarning)
@@ -639,8 +638,8 @@ class JsonRequest(WebRequest):
if not isinstance(exception, SessionExpiredException):
if exception.args and exception.args[0] == "bus.Bus not available in test mode":
_logger.info(exception)
- elif isinstance(exception, (odoo.exceptions.Warning, odoo.exceptions.except_orm,
- werkzeug.exceptions.NotFound)):
+ elif isinstance(exception, (odoo.exceptions.UserError,
+ werkzeug.exceptions.NotFound)):
_logger.warning(exception)
else:
_logger.exception("Exception during JSON request handling.")
@@ -696,31 +695,13 @@ class JsonRequest(WebRequest):
def serialize_exception(e):
- tmp = {
+ return {
"name": type(e).__module__ + "." + type(e).__name__ if type(e).__module__ else type(e).__name__,
"debug": traceback.format_exc(),
"message": ustr(e),
"arguments": e.args,
- "exception_type": "internal_error",
"context": getattr(e, 'context', {}),
}
- if isinstance(e, odoo.exceptions.UserError):
- tmp["exception_type"] = "user_error"
- elif isinstance(e, odoo.exceptions.Warning):
- tmp["exception_type"] = "warning"
- elif isinstance(e, odoo.exceptions.RedirectWarning):
- tmp["exception_type"] = "warning"
- elif isinstance(e, odoo.exceptions.AccessError):
- tmp["exception_type"] = "access_error"
- elif isinstance(e, odoo.exceptions.MissingError):
- tmp["exception_type"] = "missing_error"
- elif isinstance(e, odoo.exceptions.AccessDenied):
- tmp["exception_type"] = "access_denied"
- elif isinstance(e, odoo.exceptions.ValidationError):
- tmp["exception_type"] = "validation_error"
- elif isinstance(e, odoo.exceptions.except_orm):
- tmp["exception_type"] = "except_orm"
- return tmp
class HttpRequest(WebRequest):
diff --git a/odoo/models.py b/odoo/models.py
index 67aacc33417..927263f2025 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -342,7 +342,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
# default values for _transient_vacuum()
_transient_check_count = 0
_transient_max_count = lazy_classproperty(lambda _: config.get('osv_memory_count_limit'))
- _transient_max_hours = lazy_classproperty(lambda _: config.get('osv_memory_age_limit'))
+ _transient_max_hours = lazy_classproperty(lambda _: config.get('transient_age_limit'))
CONCURRENCY_CHECK_FIELD = '__last_update'
diff --git a/odoo/osv/__init__.py b/odoo/osv/__init__.py
index 9399e4410fb..2903e8d9121 100644
--- a/odoo/osv/__init__.py
+++ b/odoo/osv/__init__.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from . import osv
diff --git a/odoo/osv/osv.py b/odoo/osv/osv.py
deleted file mode 100644
index dc23494450b..00000000000
--- a/odoo/osv/osv.py
+++ /dev/null
@@ -1,14 +0,0 @@
-# -*- coding: utf-8 -*-
-# Part of Odoo. See LICENSE file for full copyright and licensing details.
-
-from ..exceptions import except_orm
-from ..models import Model, TransientModel, AbstractModel
-
-# Deprecated, kept for backward compatibility.
-# openerp.exceptions.Warning should be used instead.
-except_osv = except_orm
-
-# Deprecated, kept for backward compatibility.
-osv = Model
-osv_memory = TransientModel
-osv_abstract = AbstractModel # ;-)
diff --git a/odoo/service/model.py b/odoo/service/model.py
index 82a32c2cfc1..731007abd23 100644
--- a/odoo/service/model.py
+++ b/odoo/service/model.py
@@ -9,7 +9,7 @@ import threading
import time
import odoo
-from odoo.exceptions import UserError, ValidationError, QWebException
+from odoo.exceptions import UserError, ValidationError
from odoo.models import check_method_name
from odoo.tools.translate import translate, translate_sql_constraint
from odoo.tools.translate import _
@@ -91,13 +91,7 @@ def check(f):
if odoo.registry(dbname)._init and not odoo.tools.config['test_enable']:
raise odoo.exceptions.Warning('Currently, this database is not fully loaded and can not be used.')
return f(dbname, *args, **kwargs)
- except (OperationalError, QWebException) as e:
- if isinstance(e, QWebException):
- cause = e.qweb.get('cause')
- if isinstance(cause, OperationalError):
- e = cause
- else:
- raise
+ except OperationalError as e:
# Automatically retry the typical transaction serialization errors
if e.pgcode not in PG_CONCURRENCY_ERRORS_TO_RETRY:
raise
diff --git a/odoo/service/wsgi_server.py b/odoo/service/wsgi_server.py
index 65ca8806df9..c2712203804 100644
--- a/odoo/service/wsgi_server.py
+++ b/odoo/service/wsgi_server.py
@@ -35,22 +35,14 @@ RPC_FAULT_CODE_ACCESS_DENIED = 3
RPC_FAULT_CODE_ACCESS_ERROR = 4
def xmlrpc_handle_exception_int(e):
- if isinstance(e, odoo.exceptions.UserError):
- fault = xmlrpclib.Fault(RPC_FAULT_CODE_WARNING, odoo.tools.ustr(e.name))
- elif isinstance(e, odoo.exceptions.RedirectWarning):
+ if isinstance(e, odoo.exceptions.RedirectWarning):
fault = xmlrpclib.Fault(RPC_FAULT_CODE_WARNING, str(e))
- elif isinstance(e, odoo.exceptions.MissingError):
- fault = xmlrpclib.Fault(RPC_FAULT_CODE_WARNING, str(e))
- elif isinstance (e, odoo.exceptions.AccessError):
+ elif isinstance(e, odoo.exceptions.AccessError):
fault = xmlrpclib.Fault(RPC_FAULT_CODE_ACCESS_ERROR, str(e))
elif isinstance(e, odoo.exceptions.AccessDenied):
fault = xmlrpclib.Fault(RPC_FAULT_CODE_ACCESS_DENIED, str(e))
- elif isinstance(e, odoo.exceptions.DeferredException):
- info = e.traceback
- # Which one is the best ?
- formatted_info = "".join(traceback.format_exception(*info))
- #formatted_info = odoo.tools.exception_to_unicode(e) + '\n' + info
- fault = xmlrpclib.Fault(RPC_FAULT_CODE_APPLICATION_ERROR, formatted_info)
+ elif isinstance(e, odoo.exceptions.UserError):
+ fault = xmlrpclib.Fault(RPC_FAULT_CODE_WARNING, str(e))
else:
info = sys.exc_info()
# Which one is the best ?
@@ -61,9 +53,7 @@ def xmlrpc_handle_exception_int(e):
return xmlrpclib.dumps(fault, allow_none=None)
def xmlrpc_handle_exception_string(e):
- if isinstance(e, odoo.exceptions.UserError):
- fault = xmlrpclib.Fault('warning -- %s\n\n%s' % (e.name, e.value), '')
- elif isinstance(e, odoo.exceptions.RedirectWarning):
+ if isinstance(e, odoo.exceptions.RedirectWarning):
fault = xmlrpclib.Fault('warning -- Warning\n\n' + str(e), '')
elif isinstance(e, odoo.exceptions.MissingError):
fault = xmlrpclib.Fault('warning -- MissingError\n\n' + str(e), '')
@@ -71,10 +61,8 @@ def xmlrpc_handle_exception_string(e):
fault = xmlrpclib.Fault('warning -- AccessError\n\n' + str(e), '')
elif isinstance(e, odoo.exceptions.AccessDenied):
fault = xmlrpclib.Fault('AccessDenied', str(e))
- elif isinstance(e, odoo.exceptions.DeferredException):
- info = e.traceback
- formatted_info = "".join(traceback.format_exception(*info))
- fault = xmlrpclib.Fault(odoo.tools.ustr(e), formatted_info)
+ elif isinstance(e, odoo.exceptions.UserError):
+ fault = xmlrpclib.Fault('warning -- UserError\n\n' + str(e), '')
#InternalError
else:
info = sys.exc_info()
diff --git a/odoo/tools/config.py b/odoo/tools/config.py
index c9f6e2556c3..a50e3a8460c 100644
--- a/odoo/tools/config.py
+++ b/odoo/tools/config.py
@@ -9,6 +9,7 @@ import glob
import os
import sys
import tempfile
+import warnings
import odoo
from os.path import expandvars, expanduser, abspath, realpath
from .. import release, conf, loglevels
@@ -280,10 +281,12 @@ class configmanager(object):
help="Force a limit on the maximum number of records kept in the virtual "
"osv_memory tables. The default is False, which means no count-based limit.",
type="int")
- group.add_option("--osv-memory-age-limit", dest="osv_memory_age_limit", my_default=1.0,
- help="Force a limit on the maximum age of records kept in the virtual "
- "osv_memory tables. This is a decimal value expressed in hours, "
- "and the default is 1 hour.",
+ group.add_option("--transient-age-limit", dest="transient_age_limit", my_default=1.0,
+ help="Time limit (decimal value in hours) records created with a "
+ "TransientModel (mosly wizard) are kept in the database. Default to 1 hour.",
+ type="float")
+ group.add_option("--osv-memory-age-limit", dest="osv_memory_age_limit", my_default=False,
+ help="Deprecated alias to the transient-age-limit option",
type="float")
group.add_option("--max-cron-threads", dest="max_cron_threads", my_default=2,
help="Maximum number of threads processing concurrently cron jobs (default 2).",
@@ -350,6 +353,7 @@ class configmanager(object):
"""
opt = self._parse_config(args)
odoo.netsvc.init_logger()
+ self._warn_deprecated_options()
odoo.modules.module.initialize_sys_path()
return opt
@@ -382,6 +386,10 @@ class configmanager(object):
"The config file '%s' selected with -c/--config doesn't exist or is not readable, "\
"use -s/--save if you want to generate it"% opt.config)
+ die(bool(opt.osv_memory_age_limit) and bool(opt.transient_memory_age_limit),
+ "the osv-memory-count-limit option cannot be used with the "
+ "transient-age-limit option, please only use the latter.")
+
# place/search the config file on Win32 near the server installation
# (../etc from the server)
# if the server is run by an unprivileged user, he has to specify location of a config file where he has the rights to write,
@@ -448,7 +456,7 @@ class configmanager(object):
'stop_after_init', 'without_demo', 'http_enable', 'syslog',
'list_db', 'proxy_mode',
'test_file', 'test_tags',
- 'osv_memory_count_limit', 'osv_memory_age_limit', 'max_cron_threads', 'unaccent',
+ 'osv_memory_count_limit', 'osv_memory_age_limit', 'transient_age_limit', 'max_cron_threads', 'unaccent',
'data_dir',
'server_wide_modules',
]
@@ -525,9 +533,16 @@ class configmanager(object):
conf.server_wide_modules = [
m.strip() for m in self.options['server_wide_modules'].split(',') if m.strip()
]
-
return opt
+ def _warn_deprecated_options(self):
+ if self.options['osv_memory_age_limit']:
+ warnings.warn(
+ "The osv-memory-age-limit is a deprecated alias to "
+ "the transient-age-limit option, please use the latter.",
+ DeprecationWarning)
+ self.options['transient_age_limit'] = self.options.pop('osv_memory_age_limit')
+
def _is_addons_path(self, path):
from odoo.modules.module import MANIFEST_NAMES
for f in os.listdir(path):
diff --git a/odoo/tools/safe_eval.py b/odoo/tools/safe_eval.py
index 460eccccae8..262928874e4 100644
--- a/odoo/tools/safe_eval.py
+++ b/odoo/tools/safe_eval.py
@@ -322,16 +322,10 @@ def safe_eval(expr, globals_dict=None, locals_dict=None, mode="eval", nocopy=Fal
c = test_expr(expr, _SAFE_OPCODES, mode=mode)
try:
return unsafe_eval(c, globals_dict, locals_dict)
- except odoo.exceptions.except_orm:
- raise
- except odoo.exceptions.Warning:
+ except odoo.exceptions.UserError:
raise
except odoo.exceptions.RedirectWarning:
raise
- except odoo.exceptions.AccessDenied:
- raise
- except odoo.exceptions.AccessError:
- raise
except werkzeug.exceptions.HTTPException:
raise
except odoo.http.AuthenticationError:
@@ -340,8 +334,6 @@ def safe_eval(expr, globals_dict=None, locals_dict=None, mode="eval", nocopy=Fal
# Do not hide PostgreSQL low-level exceptions, to let the auto-replay
# of serialized transactions work its magic
raise
- except odoo.exceptions.MissingError:
- raise
except ZeroDivisionError:
raise
except Exception as e:
diff --git a/odoo/tools/test-config-values-00.conf b/odoo/tools/test-config-values-00.conf
index 1d0bd7419fe..bcf90301708 100644
--- a/odoo/tools/test-config-values-00.conf
+++ b/odoo/tools/test-config-values-00.conf
@@ -1,3 +1,3 @@
[options]
osv_memory_count_limit = 5
-osv_memory_age_limit = 3.4
+transient_age_limit = 3.4
diff --git a/odoo/tools/test_config.py b/odoo/tools/test_config.py
index 045bcaaa9c7..2e05d288f4f 100644
--- a/odoo/tools/test_config.py
+++ b/odoo/tools/test_config.py
@@ -18,7 +18,7 @@ config_file_00 = os.path.join(os.path.dirname(__file__),'test-config-values-00.c
conf = config.configmanager()
conf.parse_config()
-assert conf['osv_memory_age_limit'] == 1.0
+assert conf['transient_age_limit'] == 1.0
assert os.path.join(conf['root_path'], 'addons') == conf['addons_path']
# 2. No config file, some command-line arguments
@@ -26,9 +26,9 @@ assert os.path.join(conf['root_path'], 'addons') == conf['addons_path']
conf = config.configmanager()
# mess with the optparse.Option definition to allow an invalid path
conf.casts['addons_path'].action = 'store'
-conf.parse_config(['--addons-path=/xyz/dont-exist', '--osv-memory-age-limit=2.3'])
+conf.parse_config(['--addons-path=/xyz/dont-exist', '--transient-age-limit=2.3'])
-assert conf['osv_memory_age_limit'] == 2.3
+assert conf['transient_age_limit'] == 2.3
assert conf['addons_path'] == '/xyz/dont-exist'
# 3. Config file, no command-line arguments
@@ -36,11 +36,11 @@ assert conf['addons_path'] == '/xyz/dont-exist'
conf = config.configmanager()
conf.parse_config(['-c', config_file_00])
-assert conf['osv_memory_age_limit'] == 3.4
+assert conf['transient_age_limit'] == 3.4
# 4. Config file, and command-line arguments
conf = config.configmanager()
-conf.parse_config(['-c', config_file_00, '--osv-memory-age-limit=2.3'])
+conf.parse_config(['-c', config_file_00, '--transient-age-limit=2.3'])
-assert conf['osv_memory_age_limit'] == 2.3
+assert conf['transient_age_limit'] == 2.3