From 2a34eda5bcc336c36e73d981d880c06dd6470474 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Fri, 12 Jun 2026 18:20:50 +0100 Subject: [PATCH] Fix ERD delete crash on stale foreign key column. #8318 (#10042) 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. --- docs/en_US/release_notes_9_16.rst | 1 + web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/en_US/release_notes_9_16.rst b/docs/en_US/release_notes_9_16.rst index ec93eb9f2..8d891e268 100644 --- a/docs/en_US/release_notes_9_16.rst +++ b/docs/en_US/release_notes_9_16.rst @@ -43,6 +43,7 @@ Bug fixes | `Issue #6308 `_ - Fix the infinite loading spinner after an idle database connection is silently dropped, by detecting stale connections and offering a reconnect dialog. | `Issue #7596 `_ - Fix the Query Tool turning into a blank white screen when the runtime has a malformed default locale, by guarding the Query History date/time formatting against the resulting RangeError. + | `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. | `Issue #9091 `_ - Fix the Query Tool re-prompting for an unsaved password in a loop and rejecting the re-entered password, by caching the entered password on the server manager when the primary connection is already established. | `Issue #9128 `_ - Fixed an issue where the object breadcrumbs popup blocked clicks on the object explorer items beneath it. | `Issue #9595 `_ - Fix missing ALTER ... SET DEFAULT statements for inherited columns in the generated table SQL/EDIT script. 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 ec3895486..117e7577b 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);