diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index eb25b70284..ff69750a8d 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Transaction.check_warnings is now a directory mapping the key to the warnings * Store target of field as relation * Remove support for Python 3.8 * Add support for Python 3.13 diff --git a/trytond/doc/ref/transaction.rst b/trytond/doc/ref/transaction.rst index d753680432..c50346f9cf 100644 --- a/trytond/doc/ref/transaction.rst +++ b/trytond/doc/ref/transaction.rst @@ -46,7 +46,8 @@ Transaction .. attribute:: Transaction.check_warnings - The set of warnings already checked. + The dictionary of warnings already checked with user and warning + name as key and a set of `Warnings ` ids. .. attribute:: Transaction.timestamp diff --git a/trytond/trytond/res/user.py b/trytond/trytond/res/user.py index 908f25de2a..307087dd44 100644 --- a/trytond/trytond/res/user.py +++ b/trytond/trytond/res/user.py @@ -981,8 +981,8 @@ class Warning_(ModelSQL, ModelView): ]) if not warnings: return True - transaction.check_warnings.add(key) - cls.delete([x for x in warnings if not x.always]) + transaction.check_warnings[key].update( + w.id for w in warnings if not w.always) return False diff --git a/trytond/trytond/transaction.py b/trytond/trytond/transaction.py index d529bdeadd..03cdbf5bc2 100644 --- a/trytond/trytond/transaction.py +++ b/trytond/trytond/transaction.py @@ -4,6 +4,7 @@ import logging import time from collections import defaultdict, deque from functools import wraps +from itertools import chain from threading import local from weakref import WeakValueDictionary @@ -187,7 +188,7 @@ class Transaction(object): self.delete_records = defaultdict(set) self.trigger_records = defaultdict(set) self.log_records = [] - self.check_warnings = set() + self.check_warnings = defaultdict(set) self.timestamp = {} self.counter = 0 self._datamanagers = [] @@ -320,10 +321,25 @@ class Transaction(object): if self.log_records: self.log_records.clear() + def _remove_warnings(self): + from trytond.pool import Pool + if self.check_warnings: + pool = Pool() + Warning_ = pool.get('res.user.warning') + with without_check_access(): + warnings = Warning_.browse( + chain.from_iterable(self.check_warnings.values())) + Warning_.delete(warnings) + self._clear_warnings() + + def _clear_warnings(self): + self.check_warnings.clear() + def commit(self): from trytond.cache import Cache try: self._store_log_records() + self._remove_warnings() if self._datamanagers: for datamanager in self._datamanagers: datamanager.tpc_begin(self) @@ -356,6 +372,7 @@ class Transaction(object): datamanager.tpc_abort(self) Cache.rollback(self) self._clear_log_records() + self._clear_warnings() if self.connection: self.connection.rollback()