From 361af238cc55403b000a029ff125e1f442849780 Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Thu, 23 Mar 2023 20:21:38 -0400 Subject: [PATCH] (core) Fix bug where duplicating a table would cause an error when a column had mismatching label and colId Test Plan: Added a test case to trigger this situation. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3832 --- sandbox/grist/test_useractions.py | 18 ++++++++++++++++++ sandbox/grist/useractions.py | 1 + 2 files changed, 19 insertions(+) diff --git a/sandbox/grist/test_useractions.py b/sandbox/grist/test_useractions.py index 19f3710f..489b7eae 100644 --- a/sandbox/grist/test_useractions.py +++ b/sandbox/grist/test_useractions.py @@ -1634,3 +1634,21 @@ class TestUserActions(test_engine.EngineTestCase): existing_times = self.engine.fetch_table('Table1').columns['E'] duplicated_times = self.engine.fetch_table('FooData').columns['E'] self.assertEqual(existing_times, duplicated_times) + + def test_duplicate_table2(self): + # This test case verifies a bug fix: when a column doesn't match its label despite + # untieColIdFromLabel being False (which is possible), ensure that duplicating still works. + + self.load_sample(self.sample) + + # This is the problem situation: "State2" doesn't match "State". It can happen legitimately in + # the wild if a second column labeled "State" is added, and then the first one removed. + self.apply_user_action(['AddTable', 'Table1', [ + {'id': 'State2', 'type': 'Text', 'label': 'State'} + ]]) + self.apply_user_action(['BulkAddRecord', 'Table1', [1], { + 'State2': ['NY'], + }]) + self.apply_user_action(['DuplicateTable', 'Table1', 'Foo', True]) + self.assertTableData('Table1', data=[["id", "State2", 'manualSort'], [1, 'NY', 1.0]]) + self.assertTableData('Foo', data=[["id", "State2", 'manualSort'], [1, 'NY', 1.0]]) diff --git a/sandbox/grist/useractions.py b/sandbox/grist/useractions.py index cb2cf81c..4f387fd6 100644 --- a/sandbox/grist/useractions.py +++ b/sandbox/grist/useractions.py @@ -1904,6 +1904,7 @@ class UserActions(object): type=new_type, visibleCol=new_visible_col, untieColIdFromLabel=existing_column.untieColIdFromLabel, + colId=new_column.colId, # To ensure untieColIdFromLabel doesn't rename this column. recalcWhen=existing_column.recalcWhen, recalcDeps=new_recalc_deps, formula=formula_updates.get(new_column, existing_column.formula),