mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(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:
parent
a94905dd0a
commit
cf9e0585a9
@ -94,6 +94,10 @@ class DocActions(object):
|
|||||||
# anything that depends on them).
|
# anything that depends on them).
|
||||||
self._engine.invalidate_records(table_id, row_ids, col_ids=columns.keys())
|
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):
|
def ReplaceTableData(self, table_id, row_ids, column_values):
|
||||||
old_data = self._engine.fetch_table(table_id, formulas=False)
|
old_data = self._engine.fetch_table(table_id, formulas=False)
|
||||||
|
@ -667,3 +667,33 @@ class TestTriggerFormulas(test_engine.EngineTestCase):
|
|||||||
self.assertFormulaError(error, ZeroDivisionError, 'float division by zero')
|
self.assertFormulaError(error, ZeroDivisionError, 'float division by zero')
|
||||||
self.assertEqual(error._message, 'float division by zero')
|
self.assertEqual(error._message, 'float division by zero')
|
||||||
self.assertEqual(error.details, objtypes.RaisedException(ZeroDivisionError()).no_traceback().details)
|
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
|
||||||
|
])
|
||||||
|
@ -581,10 +581,6 @@ class UserActions(object):
|
|||||||
self._docmodel.update([f for c in type_changed for f in c.viewFields],
|
self._docmodel.update([f for c in type_changed for f in c.viewFields],
|
||||||
widgetOptions='', displayCol=0)
|
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)
|
self.doBulkUpdateFromPairs(table_id, update_pairs)
|
||||||
|
|
||||||
for table_id in rebuild_summary_tables:
|
for table_id in rebuild_summary_tables:
|
||||||
|
Loading…
Reference in New Issue
Block a user