changeset 373241e8cc54 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=373241e8cc54
description:
Make warning check re-entrant
issue11341
review354821002
diffstat:
CHANGELOG | 1 +
doc/ref/transaction.rst | 4 +++
trytond/res/user.py | 4 +++
trytond/tests/test_res.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++
trytond/transaction.py | 2 +
5 files changed, 66 insertions(+), 0 deletions(-)
diffs (133 lines):
diff -r 6a3276538c20 -r 373241e8cc54 CHANGELOG
--- a/CHANGELOG Fri Apr 08 09:47:53 2022 +0200
+++ b/CHANGELOG Fri Apr 08 09:50:47 2022 +0200
@@ -1,3 +1,4 @@
+* Make warning check re-entrant
* Manage DatabaseDataError in ModelSQL
* Remove support for pysqlite2
* Do not import empty One2Many data
diff -r 6a3276538c20 -r 373241e8cc54 doc/ref/transaction.rst
--- a/doc/ref/transaction.rst Fri Apr 08 09:47:53 2022 +0200
+++ b/doc/ref/transaction.rst Fri Apr 08 09:50:47 2022 +0200
@@ -35,6 +35,10 @@
.. attribute:: Transaction.trigger_records
+.. attribute:: Transaction.check_warnings
+
+ The set of warnings already checked.
+
.. attribute:: Transaction.timestamp
.. attribute:: Transaction.started_at
diff -r 6a3276538c20 -r 373241e8cc54 trytond/res/user.py
--- a/trytond/res/user.py Fri Apr 08 09:47:53 2022 +0200
+++ b/trytond/res/user.py Fri Apr 08 09:50:47 2022 +0200
@@ -1089,12 +1089,16 @@
context = transaction.context
if not user or context.get('_skip_warnings'):
return False
+ key = (user, warning_name)
+ if key in transaction.check_warnings:
+ return False
warnings = cls.search([
('user', '=', user),
('name', '=', warning_name),
])
if not warnings:
return True
+ transaction.check_warnings.add(key)
cls.delete([x for x in warnings if not x.always])
return False
diff -r 6a3276538c20 -r 373241e8cc54 trytond/tests/test_res.py
--- a/trytond/tests/test_res.py Fri Apr 08 09:47:53 2022 +0200
+++ b/trytond/tests/test_res.py Fri Apr 08 09:50:47 2022 +0200
@@ -8,6 +8,7 @@
PIL = None
from trytond.pool import Pool
+from trytond.transaction import Transaction
from .test_tryton import ModuleTestCase, with_transaction
@@ -29,6 +30,60 @@
self.assertIsNotNone(user.avatar)
self.assertRegex(user.avatar_url, r'/avatar/.*/([0-9a-fA-F]{12})')
+ @with_transaction()
+ def test_user_warning(self):
+ "Check user warning"
+ pool = Pool()
+ Warning_ = pool.get('res.user.warning')
+
+ self.assertTrue(Warning_.check('test'))
+
+ @with_transaction()
+ def test_user_warning_ignored(self):
+ "Check ignored user warning"
+ pool = Pool()
+ Warning_ = pool.get('res.user.warning')
+
+ user_id = Transaction().user
+ Warning_.create([{
+ 'user': user_id,
+ 'name': 'test',
+ }])
+
+ self.assertFalse(Warning_.check('test'))
+ self.assertFalse(Warning_.search([]))
+
+ @with_transaction()
+ def test_user_warning_always_ignored(self):
+ "Check always ignored user warning"
+ pool = Pool()
+ Warning_ = pool.get('res.user.warning')
+
+ user_id = Transaction().user
+ Warning_.create([{
+ 'user': user_id,
+ 'name': 'test',
+ 'always': True,
+ }])
+
+ self.assertFalse(Warning_.check('test'))
+ self.assertTrue(Warning_.search([]))
+
+ @with_transaction()
+ def test_user_warning_reentrant(self):
+ "Check re-entrant user warning"
+ pool = Pool()
+ Warning_ = pool.get('res.user.warning')
+
+ user_id = Transaction().user
+ Warning_.create([{
+ 'user': user_id,
+ 'name': 'test',
+ }])
+
+ self.assertFalse(Warning_.check('test'))
+ self.assertFalse(Warning_.check('test'))
+
def suite():
return unittest.TestLoader().loadTestsFromTestCase(ResTestCase)
diff -r 6a3276538c20 -r 373241e8cc54 trytond/transaction.py
--- a/trytond/transaction.py Fri Apr 08 09:47:53 2022 +0200
+++ b/trytond/transaction.py Fri Apr 08 09:50:47 2022 +0200
@@ -62,6 +62,7 @@
create_records = None
delete_records = None
trigger_records = None
+ check_warnings = None
timestamp = None
started_at = None
@@ -131,6 +132,7 @@
self.create_records = defaultdict(set)
self.delete_records = defaultdict(set)
self.trigger_records = defaultdict(set)
+ self.check_warnings = set()
self.timestamp = {}
self.counter = 0
self._datamanagers = []