mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
@@ -536,9 +536,17 @@ class Table(object):
|
||||
# the column named self._summary_helper_col_id is a single reference
|
||||
# or a reference list.
|
||||
lookup_value = rec if self._summary_simple else functions.CONTAINS(rec)
|
||||
return self._summary_source_table.lookup_records(**{
|
||||
result = self._summary_source_table.lookup_records(**{
|
||||
self._summary_helper_col_id: lookup_value
|
||||
})
|
||||
|
||||
# Remove rows with empty groups
|
||||
self._engine.docmodel.setAutoRemove(rec, not result)
|
||||
if not result:
|
||||
# The group is empty, tell the engine that this record will be deleted
|
||||
raise EmptySummaryRow()
|
||||
|
||||
return result
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -633,3 +641,10 @@ class Table(object):
|
||||
# creates a dependency and brings formula columns up-to-date.
|
||||
self._engine._use_node(col.node, relation, row_ids)
|
||||
return [col.get_cell_value(row_id) for row_id in row_ids]
|
||||
|
||||
|
||||
class EmptySummaryRow(Exception):
|
||||
"""
|
||||
Special exception indicating that the summary group is empty and the row should be removed.
|
||||
"""
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user