(core) Undo bug - restoring dependencies for trigger formulas

Summary: Undo wasn't restoring trigger formulas dependencies.

Test Plan: Python tests

Reviewers: alexmojaki

Reviewed By: alexmojaki

Subscribers: alexmojaki

Differential Revision: https://phab.getgrist.com/D3163
This commit is contained in:
Jarosław Sadziński 2021-12-06 14:43:20 +01:00
parent a94905dd0a
commit cf9e0585a9
3 changed files with 34 additions and 4 deletions

View File

@ -94,6 +94,10 @@ class DocActions(object):
# anything that depends on them).
self._engine.invalidate_records(table_id, row_ids, col_ids=columns.keys())
# If the column update changes its trigger-formula conditions, rebuild dependencies.
if (table_id == "_grist_Tables_column" and
("recalcWhen" in columns or "recalcDeps" in columns)):
self._engine.trigger_columns_changed()
def ReplaceTableData(self, table_id, row_ids, column_values):
old_data = self._engine.fetch_table(table_id, formulas=False)

View File

@ -667,3 +667,33 @@ class TestTriggerFormulas(test_engine.EngineTestCase):
self.assertFormulaError(error, ZeroDivisionError, 'float division by zero')
self.assertEqual(error._message, 'float division by zero')
self.assertEqual(error.details, objtypes.RaisedException(ZeroDivisionError()).no_traceback().details)
def test_undo_should_restore_dependencies(self):
"""
Test case for a bug. Undo wasn't restoring trigger formula dependencies.
"""
self.load_sample(self.sample_math)
self.add_record("Math", A=1, B=1)
self.assertTableData("Math", data=[
["id", "A", "B", "C"],
[1, 1, 1, 1/1 + 1/1],
])
# Remove deps from C.
out_actions = self.update_record("_grist_Tables_column", 3, recalcDeps=None)
# Make sure that trigger is not fired.
self.update_record("Math", 1, A=0.5)
self.assertTableData("Math", data=[
["id", "A", "B", "C"],
[1, 0.5, 1, 1/1 + 1/1], # C is not recalculated
])
# Apply undo action.
self.apply_undo_actions(out_actions.undo)
# Invoke trigger by updating A, and make sure C is updated.
self.update_record("Math", 1, A=0.2)
self.assertTableData("Math", data=[
["id", "A", "B", "C"],
[1, 0.2, 1, 1/0.2 + 1/1], # C is recalculated
])

View File

@ -581,10 +581,6 @@ class UserActions(object):
self._docmodel.update([f for c in type_changed for f in c.viewFields],
widgetOptions='', displayCol=0)
# If the column update changes its trigger-formula conditions, rebuild dependencies.
if any(("recalcWhen" in values or "recalcDeps" in values) for c, values in update_pairs):
self._engine.trigger_columns_changed()
self.doBulkUpdateFromPairs(table_id, update_pairs)
for table_id in rebuild_summary_tables: