Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits:
d2e0256f by Cédric Krier at 2023-02-19T20:58:01+01:00
Clear tasks when transaction is rollback
The tasks records are removed on rollback so there is no need to try to run
them.
- - - - -
04e9c8ee by Cédric Krier at 2023-02-19T22:13:35+01:00
Rollback and clear tasks on database error in transaction of tests
- - - - -
19dd3bae by Cédric Krier at 2023-02-19T22:12:41+01:00
Retry on database operation error when locking table on transaction start
- - - - -
b2a3ef22 by Cédric Krier at 2023-02-19T21:00:14+01:00
Enforce same company for account and invoice line in Spanish SII tests
Closes #12062
- - - - -
4 changed files:
- modules/account_es_sii/tests/test_module.py
- trytond/trytond/protocols/dispatcher.py
- trytond/trytond/tests/test_tryton.py
- trytond/trytond/transaction.py
Changes:
=====================================
modules/account_es_sii/tests/test_module.py
=====================================
@@ -44,6 +44,7 @@
('type', '=', kind),
], limit=1)
line_account, = Account.search([
+ ('company', '=', company.id),
('type.%s' % kind, '=', True),
], limit=1)
if currency is None:
@@ -59,6 +60,7 @@
'invoice_date': today,
'lines': [
('create', [{
+ 'company': company.id,
'currency': currency.id,
'account': line_account.id,
'quantity': quantity,
=====================================
trytond/trytond/protocols/dispatcher.py
=====================================
@@ -212,8 +212,9 @@
for i in inst]
except TransactionError as e:
transaction.rollback()
+ transaction.tasks.clear()
e.fix(transaction_extras)
continue
except backend.DatabaseOperationalError:
if count < retry and not rpc.readonly:
transaction.rollback()
@@ -215,8 +216,9 @@
e.fix(transaction_extras)
continue
except backend.DatabaseOperationalError:
if count < retry and not rpc.readonly:
transaction.rollback()
+ transaction.tasks.clear()
count += 1
logger.debug("Retry: %i", count)
continue
=====================================
trytond/trytond/tests/test_tryton.py
=====================================
@@ -222,6 +222,8 @@
try:
result = func(*args, **kwargs)
except TransactionError as e:
+ transaction.rollback()
+ transaction.tasks.clear()
e.fix(extras)
continue
finally:
=====================================
trytond/trytond/transaction.py
=====================================
@@ -15,6 +15,7 @@
'check_access', 'without_check_access',
'active_records', 'inactive_records']
+_retry = config.getint('database', 'retry')
_cache_transaction = config.getint('cache', 'transaction')
_cache_model = config.getint('cache', 'model')
_cache_record = config.getint('cache', 'record')
@@ -172,8 +173,6 @@
else:
database = backend.Database(database_name).connect()
Flavor.set(backend.Database.flavor)
- self.connection = database.get_connection(readonly=readonly,
- autocommit=autocommit)
self.user = user
self.database = database
self.readonly = readonly
@@ -186,10 +185,26 @@
self.timestamp = {}
self.counter = 0
self._datamanagers = []
- lock_tables = extras.get('_lock_tables', [])
- for table in lock_tables:
- self.database.lock(self.connection, table)
- self._locked_tables = set(lock_tables)
+
+ count = 0
+ while True:
+ if count:
+ time.sleep(0.002 * (_retry - count))
+ self.connection = database.get_connection(readonly=readonly,
+ autocommit=autocommit)
+ try:
+ lock_tables = extras.get('_lock_tables', [])
+ for table in lock_tables:
+ self.database.lock(self.connection, table)
+ self._locked_tables = set(lock_tables)
+ except backend.DatabaseOperationalError:
+ if count < _retry:
+ self.connection.rollback()
+ count += 1
+ logger.debug("Retry: %i", count)
+ continue
+ raise
+ break
if database_name:
from trytond.cache import Cache
Cache.sync(self)
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/781b3cf9f9d95393a87ced34ec1203075e598405...b2a3ef22873ee73cae56c8d6c4ddacc056fc7e4c
--
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/781b3cf9f9d95393a87ced34ec1203075e598405...b2a3ef22873ee73cae56c8d6c4ddacc056fc7e4c
You're receiving this email because of your account on foss.heptapod.net.