details: https://code.tryton.org/tryton/commit/2335dba4dc44
branch: default
user: Nicolas Évrard <[email protected]>
date: Fri Jun 26 15:41:27 2026 +0200
description:
Delete only the records marked to be deleted when restoring history
Closes #14913
diffstat:
trytond/trytond/model/modelsql.py | 2 +-
trytond/trytond/tests/test_history.py | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletions(-)
diffs (46 lines):
diff -r 7ed04dd10395 -r 2335dba4dc44 trytond/trytond/model/modelsql.py
--- a/trytond/trytond/model/modelsql.py Tue Jun 16 15:36:46 2026 +0200
+++ b/trytond/trytond/model/modelsql.py Fri Jun 26 15:41:27 2026 +0200
@@ -942,7 +942,7 @@
if to_delete:
cursor.execute(*table.delete(
- where=fields.SQL_OPERATORS['in'](table.id, ids)))
+ where=fields.SQL_OPERATORS['in'](table.id, to_delete)))
cls._insert_history(list(to_delete), True)
if to_update:
cls._insert_history(list(to_update))
diff -r 7ed04dd10395 -r 2335dba4dc44 trytond/trytond/tests/test_history.py
--- a/trytond/trytond/tests/test_history.py Tue Jun 16 15:36:46 2026 +0200
+++ b/trytond/trytond/tests/test_history.py Fri Jun 26 15:41:27 2026 +0200
@@ -239,6 +239,30 @@
self.assertEqual(history.dico, {'a': 1})
@with_transaction()
+ def test_restore_history_with_deletion(self):
+ "Test restoring records when some should be deleted"
+ pool = Pool()
+ History = pool.get('test.history')
+ transaction = Transaction()
+
+ history = History(value=1)
+ history.save()
+ first = history.create_date
+
+ transaction.commit()
+
+ history_2 = History(value=2)
+ history_2.save()
+
+ transaction.commit()
+
+ History.restore_history([history.id, history_2.id], first)
+ History.read([history.id], {'value'})
+
+ with self.assertRaises(AccessError):
+ History.read([history_2.id], ['value'])
+
+ @with_transaction()
def test_restore_history_before(self):
'Test restore history before'
pool = Pool()