Skip to content

Prevent foreign-key header crash when adding a table column - #10735

Closed
mvanhorn wants to merge 1 commit into
pgadmin-org:masterfrom
mvanhorn:fix/10700-table-column-foreign-key-header
Closed

mvanhorn wants to merge 1 commit into
pgadmin-org:masterfrom
mvanhorn:fix/10700-table-column-foreign-key-header

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Adding a column in the table editor can crash the dialog before the foreign key editor has been opened.

The foreign key dependency callback handled a table-column ADD_ROW event and then fell through into the separate mapping-addition branch. That branch accessed the foreign key header's references value even when the header state had not been initialized.

Summary

Makes the mapping-addition branch an else-if so table-column events cannot enter it. Adds regression coverage for preserving mappings and header state, handling removed foreign keys, and retaining reference capture and header locking when adding mappings. Adds table-editor tests for adding a column before opening the foreign key editor, with and without an existing foreign key.

How it was tested

  • In web/, ran yarn jest regression/javascript/schema_ui_files/foreign_key.ui.spec.js regression/javascript/schema_ui_files/table.ui.spec.js: 35 of 35 tests pass with this change.
  • Ran the same two spec files with the fix reverted (base fa4a008): 3 of the new tests fail, including the TypeError reading 'references' from the issue.
  • A full make check did not finish locally within 10 minutes (webpack build), so I am relying on CI for the rest of the suite.

Closes #10700

AI was used for assistance.

Makes the mapping-addition branch an else-if so table-column events
cannot enter it. Adds regression coverage for preserving mappings and
header state, handling removed foreign keys, and retaining reference
capture and header locking when adding mappings. Adds table-editor tests
for adding a column before opening the foreign key editor, with and
without an existing foreign key.

Fixes pgadmin-org#10700
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The foreign-key dependency handler now treats table-column synchronization and row addition as mutually exclusive. Regression tests cover foreign-key mappings, header state, and the table editor after adding a column.

Changes

Foreign-key column addition

Layer / File(s) Summary
Dependency handling and regression coverage
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui.js, web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js, web/regression/javascript/schema_ui_files/table.ui.spec.js
The ADD_ROW branch is now mutually exclusive with table-column synchronization. Tests cover mapping and header state for column additions, including cases with and without an existing foreign key. The table UI test also checks that the new column appears and the table name remains visible.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: asheshv

Merge Risk: Minimal · up to 0f2f5

No blocking issue was identified. The reported targeted validation did not complete.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: preventing a foreign-key header crash when adding a table column.
Linked Issues check Passed Issue #10700 reports an error when adding a table field. The callback now uses an else if for mapping additions, so a table-column ADD_ROW event does not access uninitialized foreign-key header st…
Out of Scope Changes check Passed The changed source file implements the fix for issue #10700. The changes in foreign_key.ui.spec.js and table.ui.spec.js provide regression coverage for the same callback behavior and user flow. No…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #10700 reports an error when adding a table field. The callback now uses an else if for mapping additions, so a table-column ADD_ROW event does not access uninitialized foreign-key header state. Regression tests cover adding a column before opening the foreign-key editor, with and without an existing foreign key, and verify mappings, header state, and the General tab. The focused unit tests also cover mapping capture, header locking, and removed foreign keys.

Full details: Out of Scope Changes check

Explanation

The changed source file implements the fix for issue #10700. The changes in foreign_key.ui.spec.js and table.ui.spec.js provide regression coverage for the same callback behavior and user flow. No unrelated change is shown in the supplied pull-request summary or inspected files.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between dca776e and 0f2f5cd.

Files selected for processing: 3
  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui.js
  • web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js
  • web/regression/javascript/schema_ui_files/table.ui.spec.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@dpage

dpage commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Thanks! Squashed and merged as 2753415.

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.

Error occurred while adding a field

2 participants