Menu

#883 Fix ER Diagram breakage for FKs to tables needing quoted names

open
nobody
None
6 days ago
6 days ago
Anonymous
No

Originally created by: ChronicallyJD

ER Diagram generation failed with "Can not create edge with nonexistant
target" whenever a foreign key referenced a table whose name required
quoting (e.g. contained uppercase characters).

Root cause: draw_graph() keyed graph nodes by the raw, unquoted table
name from QueryTables, but built foreign-key edges from
QueryTablesForeignKeys, which returns names via quote_ident(). For names
needing quotes the node id (Testtable) and the edge target ("Testtable")
diverged, so Cytoscape could not find the target node and aborted rendering.

Fix:

  • Key nodes by the quoted identifier (name_raw), keep the unquoted name as
    the display label, and only create an edge when both endpoints reference an
    existing node.
  • Resolve FK edge endpoints by falling back to the unquoted display label
    when the FK metadata name is not a node id itself — needed because SQLite
    returns name_raw quoted for every table while its FK pragma metadata is
    unquoted. This also fixes the is_fk/is_pk column-flag lookups.
  • Fix html_id generation in the ERD tab: the sanitizing regex lacked the
    global flag, so a quoted node id kept its trailing quote and
    document.querySelector() in adjustSizes() threw on the invalid
    selector, skipping the layout run.

Testing: adds regression tests for PostgreSQL (live server) and SQLite
(temp file, no server needed). Both fail without their respective fixes and
pass with them.

Note: ERD layouts saved before this change store unquoted node ids, so
tables whose names require quoting lose their saved position once after
upgrading (they reappear via new_nodes); positions of all other tables are
preserved.

Fixes [#882]

Related

Tickets: #882

Discussion


Log in to post a comment.

Auth0 Logo