From 7c8a44ab60d032da2f39c6e6390af6839740770c Mon Sep 17 00:00:00 2001 From: Dave Page Date: Tue, 9 Jun 2026 11:56:47 +0100 Subject: [PATCH] Fix ERD delete crash on stale foreign key column. #8318 removeOneToManyLink looked up a column by the FK's stored local_column name and read .attnum unconditionally. After a column rename the stored name no longer matches, so _.find returned undefined and .attnum threw, blocking deletion of the table/link. Use optional chaining so a stale FK simply doesn't match the link being removed and deletion proceeds. Co-Authored-By: Claude Opus 4.8 (1M context) --- docs/en_US/release_notes_9_16.rst | 2 ++ web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/en_US/release_notes_9_16.rst b/docs/en_US/release_notes_9_16.rst index a7ec92e1bee..9c29f5d0c8b 100644 --- a/docs/en_US/release_notes_9_16.rst +++ b/docs/en_US/release_notes_9_16.rst @@ -25,3 +25,5 @@ Housekeeping Bug fixes ********* + + | `Issue #8318 `_ - Fixed an error ("i.default.find(...) is undefined") that prevented deleting a table or relationship link in the ERD tool when a foreign key referenced a column that had been renamed. diff --git a/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js b/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js index ec38954865c..117e7577b97 100644 --- a/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js +++ b/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js @@ -526,7 +526,7 @@ export default class ERDCore { let newForeingKeys = []; tableData.foreign_key?.forEach((theFkRow)=>{ let theFk = theFkRow.columns[0]; - let attnum = _.find(tableNode.getColumns(), (col)=>col.name==theFk.local_column).attnum; + let attnum = _.find(tableNode.getColumns(), (col)=>col.name==theFk.local_column)?.attnum; /* Skip all those whose attnum and table matches to the link */ if(linkData.local_column_attnum != attnum || linkData.referenced_table_uid != theFk.references) { newForeingKeys.push(theFkRow);