(core) Automatically remove empty summary table rows

Summary: When the `getSummarySourceGroup` function (used by the `$group` column) finds that the group is empty, raise a new special exception `EmptySummaryRow`. The engine catches this exception, avoids saving a value to the cell, and removes the record.

Test Plan: Updated several Python tests

Reviewers: georgegevoian

Reviewed By: georgegevoian

Subscribers: dsagal

Differential Revision: https://phab.getgrist.com/D3489
This commit is contained in:
Alex Hall
2022-07-07 22:43:12 +02:00
parent ddb80f111e
commit 0bdc82a170
9 changed files with 78 additions and 90 deletions

View File

@@ -221,7 +221,8 @@ class DocModel(object):
Marks a record for automatic removal. To use, create a formula in your table, e.g.
'setAutoRemove', which calls `table.docmodel.setAutoRemove(boolean_value)`. Whenever it gets
reevaluated and the boolean_value is true, the record will be automatically removed.
For now, it is only usable in metadata tables, although we could extend to user tables.
It's mostly used for metadata tables. It's also used for summary table rows with empty groups,
which requires a bit of extra care.
"""
if yes_or_no:
self._auto_remove_set.add(record)
@@ -235,7 +236,9 @@ class DocModel(object):
# Sort to make sure removals are done in deterministic order.
gone_records = sorted(self._auto_remove_set)
self._auto_remove_set.clear()
self.remove(gone_records)
# setAutoRemove is called by formulas, notably summary tables, and shouldn't be blocked by ACL.
with self._engine.user_actions.indirect_actions():
self.remove(gone_records)
return bool(gone_records)
def remove(self, records):