Backed out changeset fc478f7d7004
This commit is contained in:
1 parent
a09de147a6
commit
cfde98e54a
28 files changed
+50
-154
No files matched your search
+2
-4
@@ -721,11 +721,9 @@
|
||||
if (!(selection instanceof Array) &&
|
||||
!(key in this._values2selection)) {
|
||||
if (!jQuery.isEmptyObject(this.attributes.selection_change_with)) {
|
||||
prm = this.model.execute(
|
||||
selection, [value], {}, true, false);
|
||||
prm = this.model.execute(selection, [value]);
|
||||
} else {
|
||||
prm = this.model.execute(
|
||||
selection, [], {}, true, false);
|
||||
prm = this.model.execute(selection, []);
|
||||
}
|
||||
prm = prm.then(selection => {
|
||||
this._values2selection[key] = selection;
|
||||
|
||||
+1
-1
@@ -1226,7 +1226,7 @@
|
||||
try {
|
||||
result = this.model.execute(
|
||||
'autocomplete_' + fieldname, [values], this.get_context(),
|
||||
false, false);
|
||||
false);
|
||||
} catch (e) {
|
||||
result = [];
|
||||
}
|
||||
|
||||
@@ -113,11 +113,6 @@
|
||||
};
|
||||
|
||||
var ajax_error = function(query, status_, error) {
|
||||
if (!process_exception) {
|
||||
console.debug(`RPC error calling ${args}: ${status_}: ${error}.`);
|
||||
dfd.reject();
|
||||
return;
|
||||
}
|
||||
if (query.status == 401) {
|
||||
//Try to relog
|
||||
Sao.Session.renew(session).then(function() {
|
||||
@@ -128,11 +123,6 @@
|
||||
dfd.resolve();
|
||||
}
|
||||
}, dfd.reject);
|
||||
} else if (query.status == 408) {
|
||||
Sao.common.message.run(
|
||||
Sao.i18n.gettext('Request times out. Try again later.'),
|
||||
'tryton-error')
|
||||
.always(dfd.reject);
|
||||
} else if (query.status == 429) {
|
||||
Sao.common.message.run(
|
||||
Sao.i18n.gettext('Too many requests. Try again later.'),
|
||||
|
||||
+1
-1
@@ -1021,7 +1021,7 @@ var Sao = {
|
||||
}
|
||||
return ir_model.execute('global_search',
|
||||
[text, Sao.config.limit, Sao.main_menu_screen.model_name],
|
||||
Sao.main_menu_screen.context, true, false)
|
||||
Sao.main_menu_screen.context)
|
||||
.then(s_results => {
|
||||
var results = [];
|
||||
for (const result of s_results) {
|
||||
|
||||
+3
-4
@@ -1068,8 +1068,7 @@
|
||||
(ids.length == this.limit)) {
|
||||
count_prm = this.model.execute(
|
||||
'search_count',
|
||||
[domain, 0, this.count_limit], context,
|
||||
true, false)
|
||||
[domain, 0, this.count_limit], context)
|
||||
.then(count => {
|
||||
this.search_count = count;
|
||||
return this.search_count;
|
||||
@@ -1820,10 +1819,10 @@
|
||||
values[p] = null;
|
||||
}
|
||||
selection = this.model.execute(props.selection,
|
||||
[values], undefined, false, true);
|
||||
[values], undefined, false);
|
||||
} else {
|
||||
selection = this.model.execute(props.selection,
|
||||
[], undefined, false, true);
|
||||
[], undefined, false);
|
||||
}
|
||||
return selection.sort(function(a, b) {
|
||||
return a[1].localeCompare(b[1]);
|
||||
|
||||
@@ -1076,12 +1076,11 @@ function eval_pyson(value){
|
||||
'method': (
|
||||
'model.' + action.res_model + '.search_count'),
|
||||
'params': [
|
||||
['AND', domain, 0, tab_domain], 100, context],
|
||||
}, Sao.Session.current_session, true, false).then(
|
||||
value => {
|
||||
this._set_count(
|
||||
value, i, current, counter,
|
||||
action.name, tab_domains);
|
||||
['AND', domain, tab_domain], 0, 100, context],
|
||||
}, Sao.Session.current_session).then(value => {
|
||||
this._set_count(
|
||||
value, i, current, counter,
|
||||
action.name, tab_domains);
|
||||
});
|
||||
promesses.push(prm);
|
||||
}, this);
|
||||
@@ -1090,8 +1089,7 @@ function eval_pyson(value){
|
||||
'method': (
|
||||
'model.' + action.res_model + '.search_count'),
|
||||
'params': [domain, 0, 100, context],
|
||||
}, Sao.Session.current_session, true, false
|
||||
).then(value => {
|
||||
}, Sao.Session.current_session).then(value => {
|
||||
this._set_count(
|
||||
value, 0, current, counter,
|
||||
action.name, tab_domains);
|
||||
|
||||
@@ -1014,10 +1014,6 @@ def process_exception(exception, *args, **kwargs):
|
||||
PLOCK.release()
|
||||
if args:
|
||||
return rpc_execute(*args)
|
||||
elif exception.faultCode == str(int(HTTPStatus.REQUEST_TIMEOUT)):
|
||||
message(
|
||||
_("Request times out. Try again later."),
|
||||
msg_type=Gtk.MessageType.ERROR)
|
||||
elif exception.faultCode == str(int(HTTPStatus.TOO_MANY_REQUESTS)):
|
||||
message(
|
||||
_('Too many requests. Try again later.'),
|
||||
|
||||
@@ -30,13 +30,10 @@ class SelectionMixin(object):
|
||||
and key not in self._values2selection):
|
||||
try:
|
||||
if self.attrs.get('selection_change_with'):
|
||||
selection = RPCExecute(
|
||||
'model', self.model_name, selection, value,
|
||||
process_exception=False)
|
||||
selection = RPCExecute('model', self.model_name, selection,
|
||||
value)
|
||||
else:
|
||||
selection = RPCExecute(
|
||||
'model', self.model_name, selection,
|
||||
process_exception=False)
|
||||
selection = RPCExecute('model', self.model_name, selection)
|
||||
except RPCException:
|
||||
selection = []
|
||||
self._values2selection[key] = selection
|
||||
|
||||
@@ -23,8 +23,7 @@ from tryton.common import RPCContextReload, RPCException, RPCExecute
|
||||
from tryton.common.cellrendererclickablepixbuf import (
|
||||
CellRendererClickablePixbuf)
|
||||
from tryton.config import CONFIG, TRYTON_ICON, get_config_dir
|
||||
from tryton.exceptions import (
|
||||
TrytonError, TrytonServerError, TrytonServerUnavailable)
|
||||
from tryton.exceptions import TrytonError, TrytonServerUnavailable
|
||||
from tryton.gui.window import Window
|
||||
from tryton.jsonrpc import object_hook
|
||||
from tryton.pyson import PYSONDecoder
|
||||
@@ -376,7 +375,7 @@ class Main(Gtk.Application):
|
||||
def set_result(result):
|
||||
try:
|
||||
result = result()
|
||||
except (RPCException, TrytonServerError):
|
||||
except RPCException:
|
||||
result = []
|
||||
if search_text != widget.get_text():
|
||||
if callback:
|
||||
@@ -402,8 +401,7 @@ class Main(Gtk.Application):
|
||||
|
||||
RPCExecute('model', 'ir.model', 'global_search', search_text,
|
||||
CONFIG['client.limit'], self.menu_screen.model_name,
|
||||
context=self.menu_screen.context, callback=set_result,
|
||||
process_exception=False)
|
||||
context=self.menu_screen.context, callback=set_result)
|
||||
return False
|
||||
|
||||
def changed(widget):
|
||||
|
||||
@@ -5,7 +5,6 @@ import logging
|
||||
import tryton.common as common
|
||||
from tryton.common import RPCException, RPCExecute
|
||||
from tryton.config import CONFIG
|
||||
from tryton.exceptions import TrytonServerError
|
||||
from tryton.pyson import PYSONDecoder
|
||||
|
||||
from . import field as fields
|
||||
@@ -678,9 +677,8 @@ class Record:
|
||||
try:
|
||||
res = RPCExecute(
|
||||
'model', self.model_name,
|
||||
'autocomplete_' + fieldname, args, context=self.get_context(),
|
||||
process_exception=False)
|
||||
except (RPCException, TrytonServerError):
|
||||
'autocomplete_' + fieldname, args, context=self.get_context())
|
||||
except RPCException:
|
||||
# ensure res is a list
|
||||
res = []
|
||||
self.autocompletion[fieldname] = res
|
||||
|
||||
@@ -21,7 +21,6 @@ from tryton.common import (
|
||||
from tryton.common.domain_inversion import canonicalize
|
||||
from tryton.common.domain_parser import DomainParser
|
||||
from tryton.config import CONFIG
|
||||
from tryton.exceptions import TrytonServerError
|
||||
from tryton.gui.window.infobar import InfoBar
|
||||
from tryton.gui.window.view_form.model.group import Group
|
||||
from tryton.gui.window.view_form.view import View
|
||||
@@ -309,9 +308,8 @@ class Screen:
|
||||
try:
|
||||
self.search_count = RPCExecute(
|
||||
'model', self.model_name, 'search_count',
|
||||
domain, 0, self.count_limit, context=context,
|
||||
process_exception=False)
|
||||
except (RPCException, TrytonServerError):
|
||||
domain, 0, self.count_limit, context=context)
|
||||
except RPCException:
|
||||
self.search_count = 0
|
||||
else:
|
||||
self.search_count = len(ids)
|
||||
|
||||
@@ -7,7 +7,6 @@ from gi.repository import Gtk
|
||||
import tryton.common as common
|
||||
from tryton.action import Action
|
||||
from tryton.config import CONFIG
|
||||
from tryton.exceptions import TrytonServerError
|
||||
from tryton.pyson import PYSONDecoder
|
||||
|
||||
|
||||
@@ -188,16 +187,14 @@ class Link(StateMixin, Gtk.Button):
|
||||
['AND', domain, tab_domain], 0, 100, context=context,
|
||||
callback=functools.partial(
|
||||
self._set_count, idx=i, current=self._current,
|
||||
counter=counter, label=label),
|
||||
process_exception=False)
|
||||
counter=counter, label=label))
|
||||
else:
|
||||
common.RPCExecute(
|
||||
'model', action['res_model'], 'search_count',
|
||||
domain, 0, 100, context=context,
|
||||
callback=functools.partial(
|
||||
self._set_count, current=self._current,
|
||||
counter=counter, label=label),
|
||||
process_exception=False)
|
||||
counter=counter, label=label))
|
||||
|
||||
def _set_count(self, value, idx=0, current=None, counter=None, label=''):
|
||||
if current != self._current or not self.get_parent():
|
||||
@@ -207,7 +204,7 @@ class Link(StateMixin, Gtk.Button):
|
||||
if count > 99:
|
||||
count = '99+'
|
||||
counter[idx] = count
|
||||
except (common.RPCException, TrytonServerError):
|
||||
except common.RPCException:
|
||||
pass
|
||||
self._set_label_counter(label, counter)
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
* Add timeout parameter on RPC definitions
|
||||
* Add pairwise_longest tools
|
||||
* Add support for Python 3.12
|
||||
* Support default values for autocomplete
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
RPC
|
||||
===
|
||||
|
||||
.. class:: RPC([readonly[, instantiate[, [decorator, result[, check_access[, unique[, fresh_session[, cache[, timeout]]]]]]]]])
|
||||
.. class:: RPC([readonly[, instantiate[, [decorator, result[, check_access[, unique[, fresh_session[, cache]]]]]]]])
|
||||
|
||||
Define the behavior of Remote Procedure Call.
|
||||
|
||||
@@ -46,12 +46,6 @@ Instance attributes are:
|
||||
|
||||
A :class:`RPCCache` instance to compute the cache duration for the answer.
|
||||
|
||||
.. attribute:: RPC.timeout
|
||||
|
||||
The timeout in second for the call.
|
||||
``0`` or ``None`` means no timeout is applied.
|
||||
Default is ``None``.
|
||||
|
||||
|
||||
RPCCache
|
||||
--------
|
||||
|
||||
@@ -271,13 +271,6 @@ The maximum size in bytes of an authenticated request (zero means no limit).
|
||||
|
||||
Default: 2GB
|
||||
|
||||
timeout
|
||||
~~~~~~~
|
||||
|
||||
The timeout in seconds before aborting requests that have their execution time
|
||||
depending on the parameters.
|
||||
|
||||
Default: ``60``
|
||||
|
||||
cache
|
||||
-----
|
||||
|
||||
@@ -12,8 +12,7 @@ from trytond.config import config
|
||||
|
||||
__all__ = [
|
||||
'name', 'Database', 'TableHandler',
|
||||
'DatabaseIntegrityError', 'DatabaseDataError', 'DatabaseOperationalError',
|
||||
'DatabaseTimeoutError']
|
||||
'DatabaseIntegrityError', 'DatabaseDataError', 'DatabaseOperationalError']
|
||||
|
||||
|
||||
name = urllib.parse.urlparse(config.get('database', 'uri', default='')).scheme
|
||||
@@ -35,5 +34,4 @@ Database = _module.Database
|
||||
DatabaseIntegrityError = _module.DatabaseIntegrityError
|
||||
DatabaseDataError = _module.DatabaseDataError
|
||||
DatabaseOperationalError = _module.DatabaseOperationalError
|
||||
DatabaseTimeoutError = _module.DatabaseTimeoutError
|
||||
TableHandler = _module.TableHandler
|
||||
@@ -6,7 +6,6 @@ from sql import For
|
||||
|
||||
DatabaseIntegrityError = None
|
||||
DatabaseOperationalError = None
|
||||
DatabaseTimeoutError = None
|
||||
|
||||
SQLType = namedtuple('SQLType', 'base type')
|
||||
|
||||
@@ -27,8 +26,7 @@ class DatabaseInterface(object):
|
||||
def connect(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_connection(
|
||||
self, autocommit=False, readonly=False, statement_timeout=None):
|
||||
def get_connection(self, autocommit=False, readonly=False):
|
||||
raise NotImplementedError
|
||||
|
||||
def put_connection(self, connection, close=False):
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
|
||||
from .database import (
|
||||
Database, DatabaseDataError, DatabaseIntegrityError,
|
||||
DatabaseOperationalError, DatabaseTimeoutError)
|
||||
DatabaseOperationalError)
|
||||
from .table import TableHandler
|
||||
|
||||
__all__ = [
|
||||
Database, TableHandler,
|
||||
DatabaseIntegrityError, DatabaseDataError, DatabaseOperationalError,
|
||||
DatabaseTimeoutError]
|
||||
DatabaseIntegrityError, DatabaseDataError, DatabaseOperationalError]
|
||||
@@ -26,7 +26,6 @@ from psycopg2 import DataError as DatabaseDataError
|
||||
from psycopg2 import IntegrityError as DatabaseIntegrityError
|
||||
from psycopg2 import OperationalError as DatabaseOperationalError
|
||||
from psycopg2 import ProgrammingError
|
||||
from psycopg2.errors import QueryCanceled as DatabaseTimeoutError
|
||||
from psycopg2.extras import register_default_json, register_default_jsonb
|
||||
from sql import Cast, Flavor, For, Table
|
||||
from sql.conditionals import Coalesce
|
||||
@@ -39,8 +38,7 @@ from trytond.tools.gevent import is_gevent_monkey_patched
|
||||
|
||||
__all__ = [
|
||||
'Database',
|
||||
'DatabaseIntegrityError', 'DatabaseDataError', 'DatabaseOperationalError',
|
||||
'DatabaseTimeoutError']
|
||||
'DatabaseIntegrityError', 'DatabaseDataError', 'DatabaseOperationalError']
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -256,8 +254,7 @@ class Database(DatabaseInterface):
|
||||
def connect(self):
|
||||
return self
|
||||
|
||||
def get_connection(
|
||||
self, autocommit=False, readonly=False, statement_timeout=None):
|
||||
def get_connection(self, autocommit=False, readonly=False):
|
||||
retry = max(config.getint('database', 'retry'), _maxconn)
|
||||
for count in range(retry, -1, -1):
|
||||
try:
|
||||
@@ -277,13 +274,8 @@ class Database(DatabaseInterface):
|
||||
isolation_level=ISOLATION_LEVEL_REPEATABLE_READ,
|
||||
readonly=readonly,
|
||||
autocommit=autocommit)
|
||||
with conn.cursor() as cur:
|
||||
if statement_timeout:
|
||||
cur.execute('SET statement_timeout=%s' %
|
||||
(statement_timeout * 1000))
|
||||
else:
|
||||
# Detect disconnection
|
||||
cur.execute('SELECT 1')
|
||||
# Detect disconnection
|
||||
conn.cursor().execute('SELECT 1')
|
||||
except DatabaseOperationalError:
|
||||
self._connpool.putconn(conn, close=True)
|
||||
continue
|
||||
@@ -291,7 +283,6 @@ class Database(DatabaseInterface):
|
||||
return conn
|
||||
|
||||
def put_connection(self, connection, close=False):
|
||||
connection.reset()
|
||||
self._connpool.putconn(connection, close=close)
|
||||
|
||||
def close(self):
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
|
||||
from .database import (
|
||||
Database, DatabaseDataError, DatabaseIntegrityError,
|
||||
DatabaseOperationalError, DatabaseTimeoutError)
|
||||
DatabaseOperationalError)
|
||||
from .table import TableHandler
|
||||
|
||||
__all__ = [
|
||||
Database, TableHandler,
|
||||
DatabaseIntegrityError, DatabaseDataError, DatabaseOperationalError,
|
||||
DatabaseTimeoutError]
|
||||
DatabaseIntegrityError, DatabaseDataError, DatabaseOperationalError]
|
||||
@@ -29,8 +29,7 @@ from trytond.transaction import Transaction
|
||||
|
||||
__all__ = [
|
||||
'Database',
|
||||
'DatabaseIntegrityError', 'DatabaseDataError', 'DatabaseOperationalError',
|
||||
'DatabaseTimeoutError']
|
||||
'DatabaseIntegrityError', 'DatabaseDataError', 'DatabaseOperationalError']
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_default_name = config.get('database', 'default_name', default=':memory:')
|
||||
@@ -40,10 +39,6 @@ class DatabaseDataError(DatabaseError):
|
||||
pass
|
||||
|
||||
|
||||
class DatabaseTimeoutError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class SQLiteExtract(Function):
|
||||
__slots__ = ()
|
||||
_function = 'EXTRACT'
|
||||
@@ -450,8 +445,7 @@ class Database(DatabaseInterface):
|
||||
db_uri = urllib.parse.urlunparse(db_uri)
|
||||
return db_uri.replace('sqlite', 'file', 1)
|
||||
|
||||
def get_connection(
|
||||
self, autocommit=False, readonly=False, statement_timeout=None):
|
||||
def get_connection(self, autocommit=False, readonly=False):
|
||||
if self._conn is None:
|
||||
self.connect()
|
||||
if autocommit:
|
||||
|
||||
@@ -70,7 +70,6 @@ class TrytonConfigParser(configparser.ConfigParser):
|
||||
self.set('request', 'max_size', str(2 * 1024 * 1024))
|
||||
self.set('request', 'max_size_authenticated',
|
||||
str(2 * 1024 * 1024 * 1024))
|
||||
self.set('request', 'timeout', str(60))
|
||||
self.add_section('cache')
|
||||
self.set('cache', 'transaction', '10')
|
||||
self.set('cache', 'model', '200')
|
||||
|
||||
@@ -13,7 +13,6 @@ from sql.conditionals import Case
|
||||
from sql.operators import Equal
|
||||
|
||||
from trytond.cache import Cache
|
||||
from trytond.config import config
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import (
|
||||
DeactivableMixin, EvalEnvironment, Exclude, Index, ModelSingleton,
|
||||
@@ -32,7 +31,6 @@ from trytond.wizard import Button, StateAction, StateView, Wizard
|
||||
from .resource import ResourceAccessMixin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
_request_timeout = config.getint('request', 'timeout', default=0)
|
||||
|
||||
|
||||
class ConditionError(ValidationError):
|
||||
@@ -79,7 +77,7 @@ class Model(ModelSQL, ModelView):
|
||||
'list_history': RPC(),
|
||||
'get_notification': RPC(),
|
||||
'get_names': RPC(),
|
||||
'global_search': RPC(timeout=_request_timeout),
|
||||
'global_search': RPC(),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -39,7 +39,6 @@ _cache_count_timeout = config.getint(
|
||||
'cache', 'count_timeout', default=60 * 60 * 24)
|
||||
_cache_count_clear = config.getint(
|
||||
'cache', 'count_clear', default=1000)
|
||||
_request_timeout = config.getint('request', 'timeout', default=0)
|
||||
|
||||
|
||||
def local_cache(Model, transaction=None):
|
||||
@@ -137,15 +136,11 @@ class ModelStorage(Model):
|
||||
'delete': RPC(readonly=False, instantiate=0),
|
||||
'copy': RPC(readonly=False, instantiate=0, unique=False,
|
||||
result=lambda r: list(map(int, r))),
|
||||
'search': RPC(
|
||||
result=lambda r: list(map(int, r)),
|
||||
timeout=_request_timeout),
|
||||
'search_count': RPC(timeout=_request_timeout),
|
||||
'search_read': RPC(timeout=_request_timeout),
|
||||
'resources': RPC(
|
||||
instantiate=0, unique=False,
|
||||
timeout=_request_timeout),
|
||||
'export_data_domain': RPC(timeout=_request_timeout),
|
||||
'search': RPC(result=lambda r: list(map(int, r))),
|
||||
'search_count': RPC(),
|
||||
'search_read': RPC(),
|
||||
'resources': RPC(instantiate=0, unique=False),
|
||||
'export_data_domain': RPC(),
|
||||
'export_data': RPC(instantiate=0, unique=False),
|
||||
'import_data': RPC(readonly=False),
|
||||
})
|
||||
|
||||
@@ -184,8 +184,7 @@ def _dispatch(request, pool, *args, **kwargs):
|
||||
if count:
|
||||
time.sleep(0.02 * (retry - count))
|
||||
with Transaction().start(
|
||||
pool.database_name, user,
|
||||
readonly=rpc.readonly, timeout=rpc.timeout,
|
||||
pool.database_name, user, readonly=rpc.readonly,
|
||||
**transaction_extras) as transaction:
|
||||
try:
|
||||
c_args, c_kwargs, transaction.context, transaction.timestamp \
|
||||
@@ -208,9 +207,6 @@ def _dispatch(request, pool, *args, **kwargs):
|
||||
transaction.tasks.clear()
|
||||
e.fix(transaction_extras)
|
||||
continue
|
||||
except backend.DatabaseTimeoutError:
|
||||
logger.warning(log_message, *log_args, exc_info=True)
|
||||
abort(HTTPStatus.REQUEST_TIMEOUT)
|
||||
except backend.DatabaseOperationalError:
|
||||
if count < retry and not rpc.readonly:
|
||||
transaction.rollback()
|
||||
|
||||
@@ -21,12 +21,11 @@ class RPC(object):
|
||||
|
||||
__slots__ = (
|
||||
'readonly', 'instantiate', 'decorator', 'result',
|
||||
'check_access', 'fresh_session', 'unique', 'cache', 'timeout')
|
||||
'check_access', 'fresh_session', 'unique', 'cache')
|
||||
|
||||
def __init__(
|
||||
self, readonly=True, instantiate=None, decorator=None, result=None,
|
||||
check_access=True, fresh_session=False, unique=True, cache=None,
|
||||
timeout=None):
|
||||
check_access=True, fresh_session=False, unique=True, cache=None):
|
||||
self.readonly = readonly
|
||||
self.instantiate = instantiate
|
||||
self.decorator = decorator
|
||||
@@ -41,7 +40,6 @@ class RPC(object):
|
||||
if not isinstance(cache, RPCCache):
|
||||
cache = RPCCache(**cache)
|
||||
self.cache = cache
|
||||
self.timeout = timeout
|
||||
|
||||
def convert(self, obj, *args, **kwargs):
|
||||
args = list(args)
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
from trytond import backend
|
||||
from trytond.tests.test_tryton import CONTEXT, DB_NAME, USER, activate_module
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
@@ -122,26 +121,3 @@ class TransactionTestCase(unittest.TestCase):
|
||||
dm.tpc_vote.assert_not_called()
|
||||
dm.tpc_abort.assert_called_once_with(transaction)
|
||||
dm.tpc_finish.assert_not_called()
|
||||
|
||||
@unittest.skipUnless(backend.name == 'postgresql', "Test pg_settings")
|
||||
def test_postgresl_statement_timeout(self):
|
||||
get_timeout = (
|
||||
"SELECT setting FROM pg_settings "
|
||||
"WHERE name='statement_timeout'")
|
||||
|
||||
with Transaction().start(DB_NAME, USER) as transaction:
|
||||
cursor = transaction.connection.cursor()
|
||||
cursor.execute(get_timeout)
|
||||
self.assertEqual('0', cursor.fetchone()[0])
|
||||
|
||||
with Transaction().start(DB_NAME, USER, timeout=1) as transaction:
|
||||
cursor = transaction.connection.cursor()
|
||||
cursor.execute(get_timeout)
|
||||
self.assertEqual('1000', cursor.fetchone()[0])
|
||||
|
||||
@unittest.skipUnless(backend.name == 'postgresql', "Use pg_sleep")
|
||||
def test_postgresql_statement_timeout_exception(self):
|
||||
with self.assertRaises(backend.DatabaseTimeoutError):
|
||||
with Transaction().start(DB_NAME, USER, timeout=1) as transaction:
|
||||
cursor = transaction.connection.cursor()
|
||||
cursor.execute("SELECT pg_sleep(2)")
|
||||
@@ -159,7 +159,7 @@ class Transaction(object):
|
||||
return cache
|
||||
|
||||
def start(self, database_name, user, readonly=False, context=None,
|
||||
close=False, autocommit=False, timeout=None, **extras):
|
||||
close=False, autocommit=False, **extras):
|
||||
'''
|
||||
Start transaction
|
||||
'''
|
||||
@@ -197,7 +197,7 @@ class Transaction(object):
|
||||
if count:
|
||||
time.sleep(0.002 * (_retry - count))
|
||||
self.connection = database.get_connection(readonly=readonly,
|
||||
autocommit=autocommit, statement_timeout=timeout)
|
||||
autocommit=autocommit)
|
||||
try:
|
||||
lock_tables = extras.get('_lock_tables', [])
|
||||
for table in lock_tables:
|
||||
|
||||
Reference in new issue
Block a user