From 5834e156f06e4e7b879966d8b69ec64833532c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Fri, 26 Jun 2026 15:41:27 +0200 Subject: [PATCH] Delete only the records marked to be deleted when restoring history Closes #14913 (grafted from 2335dba4dc447dbcae94d99097911460439ef02a) --HG-- branch : 8.0 --- trytond/trytond/model/modelsql.py | 2 +- trytond/trytond/tests/test_history.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/trytond/trytond/model/modelsql.py b/trytond/trytond/model/modelsql.py index b406566cf2..62f4d0fa9f 100644 --- a/trytond/trytond/model/modelsql.py +++ b/trytond/trytond/model/modelsql.py @@ -942,7 +942,7 @@ class ModelSQL(ModelStorage): 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 --git a/trytond/trytond/tests/test_history.py b/trytond/trytond/tests/test_history.py index 98a44e56a8..d9b7cf25fa 100644 --- a/trytond/trytond/tests/test_history.py +++ b/trytond/trytond/tests/test_history.py @@ -238,6 +238,30 @@ class HistoryTestCase(TestCase): history = History(history_id) 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'