(core) Fix some bugs with ChoiceList in summary tables, and evaluation of lookups.

Summary:
Addresses several issues:
- Error 'Cannot modify summary group-by column' when changing Text ->
  ChoiceList in the presence of summary tables.
- Error 'ModifyColumn in unexpected position' when changing ChoiceList -> Text
  in the presence of summary tables.
- Double-evaluation of trigger formulas in some cases.

Fixes include:
- Fixed verification that summary group-by columns match the underlying ones,
  and added comments to explain.
- Avoid updating non-metadata lookups after each doc-action (early lookups
  generated extra actions to populate summary tables, causing the 'ModifyColumn
  in unexpected position' bug)
- When updating formulas, do update lookups first.
- Made a client-side tweak to avoid a JS error in case of some undos.

Solution to reduce lookups is based on https://phab.getgrist.com/D3069?vs=on&id=12445,
and tests for double-evaluation of trigger formulas are taken from there.

Add a new test case to protect against bugs caused by incorrect order of
evaluating #lookup columns.

Enhanced ChoiceList browser test to check a conversion scenario in the presence
of summary tables, previously triggering bugs.

Test Plan: Various tests added or enhanced.

Reviewers: alexmojaki

Reviewed By: alexmojaki

Subscribers: jarek

Differential Revision: https://phab.getgrist.com/D3184
This commit is contained in:
Dmitry S
2021-12-15 09:50:55 -05:00
parent 65ac8aaa85
commit f024aaaf5d
8 changed files with 133 additions and 44 deletions

View File

@@ -557,13 +557,25 @@ class UserActions(object):
update_pairs = col_updates.items()
# Disallow most changes to summary group-by columns, except to match the underlying column.
# TODO: This is poor. E.g. renaming a group-by column could rename the underlying column (or
# offer the option to), or could be disabled; either would be better than an error.
for col, values in update_pairs:
if col.summarySourceCol:
underlying = col_updates.get(col.summarySourceCol, {})
if not all(value == getattr(col, key) or has_value(underlying, key, value)
for key, value in six.iteritems(values)
if key not in ('displayCol', 'visibleCol')):
raise ValueError("Cannot modify summary group-by column '%s'" % col.colId)
underlying_updates = col_updates.get(col.summarySourceCol, {})
for key, value in six.iteritems(values):
if key in ('displayCol', 'visibleCol'):
# These can't always match the underlying column, and can now be changed in the
# group-by column. (Perhaps the same should be permitted for all widget options.)
continue
# Properties like colId and type ought to match those of the underlying column (either
# the current ones, or the ones that the underlying column is being changed to).
expected = underlying_updates.get(key, getattr(col, key))
if key == 'type':
# Type sometimes must differ (e.g. ChoiceList -> Choice).
expected = summary.summary_groupby_col_type(expected)
if value != expected:
raise ValueError("Cannot modify summary group-by column '%s'" % col.colId)
make_acl_updates = acl.prepare_acl_col_renames(self._docmodel, self, renames)