(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

@@ -997,7 +997,8 @@ class UserActions(object):
def BulkRemoveRecord(self, table_id, row_ids):
# table_rec will not be found for metadata tables, but they are not summary tables anyway.
table_rec = self._docmodel.tables.lookupOne(tableId=table_id)
if table_rec and table_rec.summarySourceTable:
# docmodel.setAutoRemove is used for empty summary table rows, but does so 'indirectly'
if table_rec and table_rec.summarySourceTable and self._indirection_level == DIRECT_ACTION:
raise ValueError("Cannot remove record from summary table")
method = self._overrides.get(('BulkRemoveRecord', table_id), self.doBulkRemoveRecord)