Skip to content

Fix ERD delete crash on a stale foreign-key column (#8318)#10042

Open
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix-8318-erd-delete-crash
Open

Fix ERD delete crash on a stale foreign-key column (#8318)#10042
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix-8318-erd-delete-crash

Conversation

@dpage

@dpage dpage commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #8318.

Deleting a table or relationship link in the ERD tool could fail with i.default.find(...) is undefined (a removeOneToManyLink stack trace), blocking the delete.

Root cause: removeOneToManyLink (ERDCore.js:529) did _.find(tableNode.getColumns(), (col)=>col.name==theFk.local_column).attnum. If a column was renamed, the FK's stored local_column no longer matches any current column, so _.find returns undefined and .attnum throws — and the link removal code below it never runs.

Fix: use optional chaining (?.attnum). A stale FK then simply doesn't match the link's attnum, and the link is removed as expected.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Added release notes for pgAdmin 4 version 9.16 with support for PostgreSQL 13–18 and bundled utilities.
  • Bug Fixes

    • Fixed ERD tool crash when deleting relationships with renamed foreign-key columns.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@dpage, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 7 minutes and 20 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3be73730-9758-4217-9e10-24d85e3c7648

📥 Commits

Reviewing files that changed from the base of the PR and between ee6e8dc and 7c8a44a.

📒 Files selected for processing (2)
  • docs/en_US/release_notes_9_16.rst
  • web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js

Walkthrough

This PR fixes an ERD tool crash that occurs when deleting links after renaming columns, by adding null-safe optional chaining to the column lookup. The fix is documented in pgAdmin 4.9.16 release notes, which list supported database versions and bundled PostgreSQL utility versions.

Changes

ERD Tool Bug Fix and 9.16 Release Documentation

Layer / File(s) Summary
ERD tool deletion fix for renamed columns
web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js
removeOneToManyLink uses optional chaining (?.attnum) to safely retrieve the column's attribute number, preventing crashes when a foreign key's local column is not found due to prior renames.
9.16 Release notes with ERD bug fix documentation
docs/en_US/release_notes_9_16.rst, docs/en_US/release_notes.rst
New release notes document version 9.16 with supported database versions (PostgreSQL and EDB Advanced Server 13–18), bundled utilities (psql/pg_dump/pg_dumpall/pg_restore 18.2), and reference issue #8318 ERD deletion fix. Toctree updated to expose the new release notes entry.

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: fixing a crash in the ERD tool when deleting items that have stale foreign-key column references, with direct reference to the issue being fixed.
Linked Issues check ✅ Passed The PR successfully addresses issue #8318 by implementing optional chaining (?.attnum) in removeOneToManyLink to handle stale foreign-key columns, preventing crashes during table/link deletion as required.
Out of Scope Changes check ✅ Passed All changes are within scope: ERDCore.js fix targets the crash bug, release notes document the fix, and toctree entry properly references the version notes—no extraneous modifications found.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js (1)

379-379: 💤 Low value

Consider applying optional chaining to other column lookups.

While the fix on line 529 correctly addresses the reported deletion crash, there are several other locations in this file where _.find(...).attnum or _.find(...).name patterns are used without optional chaining. These could potentially crash in similar scenarios:

  • Line 379: _.find(tableData.columns, ...).name
  • Lines 412-413: _.find(...).attnum in addLink
  • Lines 475-476: _.find(...).name in addOneToManyLink
  • Line 506: _.find(...).name
  • Lines 712-715, 718-720: _.find(...).attnum in addLinksBetweenNodes

Consider adding optional chaining (?.) to these lookups as well, with appropriate fallback handling when columns are not found (e.g., early return, validation error, or skipping the operation).

Also applies to: 412-413, 475-476, 506-506, 712-720

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js` at line 379, Several
lookups like fkColumn.referenced = _.find(tableData.columns,
(colm)=>colm.attnum==attnum).name and other similar patterns in addLink,
addOneToManyLink, and addLinksBetweenNodes can throw when _.find returns
undefined; update each of these to use optional chaining (e.g., _.find(...)?
.name or ? .attnum) and add a safe fallback/validation: if the find returns
undefined then either return early, log/throw a clear validation error, or skip
the operation so the code won’t crash; specifically change the
fkColumn.referenced assignment and all _.find(...).attnum/.name usages inside
addLink, addOneToManyLink, addLinksBetweenNodes to use ?., check the result, and
handle the missing-column case consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js`:
- Line 379: Several lookups like fkColumn.referenced = _.find(tableData.columns,
(colm)=>colm.attnum==attnum).name and other similar patterns in addLink,
addOneToManyLink, and addLinksBetweenNodes can throw when _.find returns
undefined; update each of these to use optional chaining (e.g., _.find(...)?
.name or ? .attnum) and add a safe fallback/validation: if the find returns
undefined then either return early, log/throw a clear validation error, or skip
the operation so the code won’t crash; specifically change the
fkColumn.referenced assignment and all _.find(...).attnum/.name usages inside
addLink, addOneToManyLink, addLinksBetweenNodes to use ?., check the result, and
handle the missing-column case consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 668d2817-8250-49d8-ae30-c3d06fda8f01

📥 Commits

Reviewing files that changed from the base of the PR and between 937d34e and ee6e8dc.

📒 Files selected for processing (3)
  • docs/en_US/release_notes.rst
  • docs/en_US/release_notes_9_16.rst
  • web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js

@dpage dpage force-pushed the fix-8318-erd-delete-crash branch 2 times, most recently from 0842cfe to 16cd6de Compare June 9, 2026 11:36
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) <noreply@anthropic.com>
@dpage dpage force-pushed the fix-8318-erd-delete-crash branch from 16cd6de to 7c8a44a Compare June 9, 2026 11:37
@asheshv asheshv requested a review from Copilot June 10, 2026 14:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an ERD tool crash that occurred when deleting a table or relationship link after a foreign-key column rename left stale local_column metadata, and documents the fix in the v9.16 release notes.

Changes:

  • Prevent removeOneToManyLink from throwing when the FK’s local_column no longer matches any current column (optional chaining on the _.find(...).attnum access).
  • Add a v9.16 release note entry referencing Issue #8318.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js Avoids a delete-time crash when FK column metadata is stale by safely handling missing column lookups.
docs/en_US/release_notes_9_16.rst Adds release note entry for the ERD delete crash fix (Issue #8318).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 526 to 528
let newForeingKeys = [];
tableData.foreign_key?.forEach((theFkRow)=>{
let theFk = theFkRow.columns[0];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

i.default.find(...) is undefined when trying to delete table or link in ERD

2 participants