mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Fix error when updating summary table formulas after rename
Summary: Formulas in summary tables were being associated with the source table for automatic updating. When a table/column was renamed such that the formula needed to update to match, it would look for a column with the same colId but in the source table. Such a column might not exist which would lead to an error, or if it existed then the update would be wrong. This association was created while building formulas to display in the code view in a nested `_Summary` class, it didn't need to exist at all. So this diff simply prevents the association from being created. User report and discussion: https://grist.slack.com/archives/C0234CPPXPA/p1659717322297019 Test Plan: Extended `TestSummary.test_table_rename` Python test. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3568
This commit is contained in:
@@ -92,7 +92,10 @@ class GenCode(object):
|
||||
body = self._formula_cache.get(key)
|
||||
if body is None:
|
||||
default = get_type_default(col_info.type)
|
||||
body = codebuilder.make_formula_body(col_info.formula, default, (table_id, col_info.colId))
|
||||
# If we have a table_id like `Table._Summary`, then we don't want to actually associate
|
||||
# this field with any real table/column.
|
||||
assoc_value = None if table_id.endswith("._Summary") else (table_id, col_info.colId)
|
||||
body = codebuilder.make_formula_body(col_info.formula, default, assoc_value)
|
||||
self._new_formula_cache[key] = body
|
||||
|
||||
decorator = ''
|
||||
@@ -147,7 +150,12 @@ class GenCode(object):
|
||||
for c in six.itervalues(s.columns) if c.isFormula)
|
||||
parts.append(indent(textbuilder.Text("\nclass _Summary:\n")))
|
||||
for col_info in six.itervalues(formulas):
|
||||
parts.append(indent(self._make_field(col_info, table_id), levels=2))
|
||||
# Associate this field with the fake table `table_id + "._Summary"`.
|
||||
# We don't know which summary table each formula belongs to, there might be several,
|
||||
# and we don't care here because this is just for display in the code view.
|
||||
# The real formula will be associated with the real summary table elsewhere.
|
||||
# Previously this field was accidentally associated with the source table, causing bugs.
|
||||
parts.append(indent(self._make_field(col_info, table_id + "._Summary"), levels=2))
|
||||
|
||||
return textbuilder.Combiner(parts)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user