From 99d0b9db78037e8c58739497a9c8751d76038613 Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Thu, 12 Sep 2024 17:57:59 -0400 Subject: [PATCH] (core) Fix bug with renames when there are dropdown conditions and some columns have null widgetOptions Summary: Error manifests as "Application Error: [Sandbox] TypeError the JSON object must be str, bytes or bytearray, not NoneType" Test Plan: Added a test case. Reviewers: georgegevoian Reviewed By: georgegevoian Subscribers: georgegevoian Differential Revision: https://phab.getgrist.com/D4347 --- sandbox/grist/dropdown_condition.py | 2 ++ .../grist/test_dropdown_condition_renames.py | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/sandbox/grist/dropdown_condition.py b/sandbox/grist/dropdown_condition.py index 409486c3..69ea0450 100644 --- a/sandbox/grist/dropdown_condition.py +++ b/sandbox/grist/dropdown_condition.py @@ -30,6 +30,8 @@ def perform_dropdown_condition_renames(useractions, renames): updates = [] for col in useractions.get_docmodel().columns.all: + if not col.widgetOptions: + continue # Find all columns in the document that have dropdown conditions. try: diff --git a/sandbox/grist/test_dropdown_condition_renames.py b/sandbox/grist/test_dropdown_condition_renames.py index 26ef29b5..06e1a2f0 100644 --- a/sandbox/grist/test_dropdown_condition_renames.py +++ b/sandbox/grist/test_dropdown_condition_renames.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long import json @@ -156,3 +157,28 @@ class TestDCRenames(test_engine.EngineTestCase): [27, 2, "features", build_dc2("identifier", "address")], ]) self.assert_invalid_formula_untouched() + + def test_rename_when_null_widget_options(self): + # Create a column with None for widget options. Just a presence of such a column was causing + # an error at one point. + self.engine.apply_user_actions([useractions.from_repr(ua) for ua in ( + ["AddColumn", "Schools", "dummy", { + "type": "Text", + "widgetOptions": None, + }], + )]) + + # Check that rename works when it needs to affect a dropdown condition. + # First check the dropdown condition before the rename. + self.assertTableData("_grist_Tables_column", cols="subset", rows="subset", data=[ + ["id", "parentId", "colId", "widgetOptions"], + [12, 2, "address", build_dc1("name", "city")], + ]) + + self.apply_user_action(["RenameColumn", "Address", "city", "area"]) + + # Check the condition got updated after the rename. + self.assertTableData("_grist_Tables_column", cols="subset", rows="subset", data=[ + ["id", "parentId", "colId", "widgetOptions"], + [12, 2, "address", build_dc1("name", "area")], + ])