fix(admin): guard find_changed_cell against cross-table schema mismatch
When switching tables, the table-switch branch writes fresh data for the new table, which re-fires the same callback with data_previous still holding the old table's rows. find_changed_cell only checked row count before diffing, so if the two tables happened to have the same number of rows it would zip mismatched-schema dicts and report a spurious changed cell (usually the PK column), producing a confusing red alert right after switching tables.
This commit is contained in:
@@ -99,6 +99,16 @@ def test_find_changed_cell_returns_none_when_identical():
|
||||
assert tables.find_changed_cell(data, data_previous) is None
|
||||
|
||||
|
||||
def test_find_changed_cell_returns_none_when_schemas_differ():
|
||||
# Mimics switching from "users" to "admin_actions" mid-callback: the two
|
||||
# tables' row lists happen to have the same length but different
|
||||
# columns, so this must not be mistaken for a genuine cell edit.
|
||||
data = [{"id": 1, "email": "a@ex.fr"}]
|
||||
data_previous = [{"id": 1, "admin_email": "x@ex.fr"}]
|
||||
|
||||
assert tables.find_changed_cell(data, data_previous) is None
|
||||
|
||||
|
||||
def test_find_changed_cell_returns_none_when_previous_is_none():
|
||||
assert tables.find_changed_cell([{"id": 1}], None) is None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user