Restore historically deleted record as deleted

issue4260
review14591002
This commit is contained in:
Cédric Krier committed 2014-10-18 09:17:09 +02:00
1 parent a7f08d8606
commit e82df70a75
2 files changed
+17 -4

No files matched your search

+8 -4
View File
@@ -305,9 +305,9 @@ class ModelSQL(ModelStorage):
history = cls.__table_history__()
columns = []
hcolumns = []
for fname, field in sorted(cls._fields.iteritems()):
if hasattr(field, 'set'):
continue
fnames = sorted(n for n, f in cls._fields.iteritems()
if not hasattr(f, 'set'))
for fname in fnames:
columns.append(Column(table, fname))
if fname == 'write_uid':
hcolumns.append(Literal(transaction.user))
@@ -316,6 +316,10 @@ class ModelSQL(ModelStorage):
else:
hcolumns.append(Column(history, fname))
def is_deleted(values):
return all(not v for n, v in zip(fnames, values)
if n not in ['id', 'write_uid', 'write_date'])
to_delete = []
to_update = []
for id_ in ids:
@@ -325,7 +329,7 @@ class ModelSQL(ModelStorage):
cursor.execute(*history.select(*hcolumns,
where=hwhere, order_by=horder, limit=1))
values = cursor.fetchone()
if not values:
if not values or is_deleted(values):
to_delete.append(id_)
else:
to_update.append(id_)
+9
View File
@@ -184,6 +184,15 @@ class HistoryTestCase(unittest.TestCase):
History.restore_history([history_id], datetime.datetime.min)
self.assertRaises(UserError, History.read, [history_id])
with Transaction().start(DB_NAME, USER, context=CONTEXT):
History.delete([History(history_id)])
transaction.cursor.commit()
with Transaction().start(DB_NAME, USER, context=CONTEXT):
History.restore_history([history_id], datetime.datetime.max)
self.assertRaises(UserError, History.read, [history_id])
@unittest.skipIf(backend.name() in ('sqlite', 'mysql'),
'now() is not the start of the transaction')
def test0045restore_history_same_timestamp(self):