From 64d9ecacdbe822622ebbb1ea3ff9144181ece088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Sadzi=C5=84ski?= Date: Wed, 8 Jun 2022 18:26:21 +0200 Subject: [PATCH] (core) Renaming table linked by summary table resulted in error Summary: When a table was selected by a summary table, renaming that table using section widget resulted in a javascript error. Test Plan: new test Reviewers: alexmojaki Reviewed By: alexmojaki Subscribers: alexmojaki Differential Revision: https://phab.getgrist.com/D3475 --- app/client/models/QuerySet.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/client/models/QuerySet.ts b/app/client/models/QuerySet.ts index a034f05a..b883f86d 100644 --- a/app/client/models/QuerySet.ts +++ b/app/client/models/QuerySet.ts @@ -335,7 +335,11 @@ export function getFilterFunc(docData: DocData, query: ClientQuery): RowFilterFu * rowIds), and consistently sorted. We use that to identify a Query across table/column renames. */ function convertQueryToRefs(docModel: DocModel, query: ClientQuery): QueryRefs { - const tableRec: any = docModel.dataTables[query.tableId].tableMetaRow; + // During table rename, we can be referencing old name of a table. + const tableRec = Object.values(docModel.dataTables).find(t => t.tableData.tableId === query.tableId)?.tableMetaRow; + if (!tableRec) { + throw new Error(`Table ${query.tableId} not found`); + } const colRefsByColId: {[colId: string]: ColRef} = {id: 'id'}; for (const col of tableRec.columns.peek().peek()) {