Skip to content

fix(sidebar): stop asking an engine with no databases to switch one - #2286

Merged
datlechin merged 2 commits into
mainfrom
fix/schema-only-container-switch
Aug 20, 2026
Merged

datlechin merged 2 commits into
mainfrom
fix/schema-only-container-switch

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #2262.

What the reporter saw

Clicking a table on a Dameng DM8 connection put up a modal sheet reading "Schema 切换失败 / This driver does not support database switching", and tables took a long time to open or never opened at all.

Root cause

Two defects compound, both in the app, neither in the Dameng plugin.

1. An empty string standing in for "no database". browsingDatabase maps an empty browse database to nil, and then three node-construction sites undo that with ?? "" and store it in a non-optional DatabaseTreeTableRef.database. Every consumer compares that against an activeDatabase that is nil-flattened. Swift promotes the left side, so ("" as String) != (nil as String?) is true, always. activate(_:) therefore fired switchDatabase(to: "") on every single table click.

2. The database-vs-schema decision was duplicated instead of centralized. switchableContainers -> ContainerSwitchPlanner is the intended chokepoint, and only switchContainer and the deep-link path used it. The sidebar tree, the tab-restore path and DatabaseManager.switchDatabase each decided for themselves, so nothing stopped a database switch on an engine that has no databases. The call reached the PluginKit default switchDatabase(to:), whose thrown message is the one in the screenshot, and the catch block rendered it as an alert titled with the engine's container entity name, which is "Schema" for Dameng.

That the cause is app-side is confirmed by OraclePlugin.swift:1126-1131, which aliases switchDatabase to switchSchema with the comment "Aliases to keep coordinator.switchDatabase working from tab restore paths without relying on a manager-side kludge." Oracle worked around this in its plugin. Dameng did not, so Dameng showed the alert.

Who was affected

Wider than Dameng. Elasticsearch, etcd and BigQuery render no Database field at all, so connection.database is always empty and every index, key or table click hit it unconditionally. Dameng's field is shown but documented optional, so it hit whenever the field was left blank. Redis, SQLite and DuckDB were unaffected because their browse database is never empty.

ContainerDropEligibility compares the same way and would fail open too, but no producer feeds it a container built from the tree's refs, so it is not reachable today. DatabaseContainerRef.database is made optional alongside the tree refs to keep it that way; the change is behaviour-neutral now and there is no CHANGELOG entry for it.

The fix

  • DatabaseTreeTableRef.database, DatabaseTreeRoutineRef.database and DatabaseContainerRef.database are String?. The "" sentinel no longer exists. Every other consumer of that comparison turned out to be safe today, each for its own local reason (a == nil short circuit, or a producer that happens to feed both sides the same string), which is precisely the kind of accident that stops holding when someone adds the next consumer.
  • MainContentCoordinator.switchContainers(database:schema:) is now the single entry point for anything naming both dimensions: the sidebar tree, "Use as Active", the tab-restore path and deep links all route through it, and it plans through ContainerSwitchPlanner.
  • A step the session has already made is skipped, decided when the step runs rather than from a snapshot taken up front. That ordering matters: on a .bySchema engine, switching database calls resetSchema and moves the session to the engine's default schema, so a schema filtered out as redundant beforehand would leave the session on dbo. This preserves the redundant-schema skip activate(_:) had and the link path never did.
  • Open Quickly no longer lists a schema-only engine's schemas a second time as databases. Those drivers answer fetchDatabases() with their schema list, so the switcher showed every schema twice and the copy labelled "Database" failed with the same driver error.
  • DatabaseManager.switchDatabase refuses an empty name rather than passing it to the driver.

Deliberately not gated on supportsDatabaseSwitching: Redis declares that flag false and still issues a real SELECT n, and Oracle aliases to a schema switch. The dimension rule is switchableContainers == [.schema], which the planner already encodes.

The second symptom: slow or stalled table opens

Independent cause, same issue. A schema switch posts currentSchemaChanged, which ran a full catalog reload plus a serial fetchTables(schema:) for every expanded schema. On these engines the browse scope is server-scoped, so both the metadata route and the execution route resolve to the session driver, and the whole reload holds sessionDriverGate.withExclusiveAccess while the clicked table's own SELECT waits behind it. Every expanded schema added a round trip to one click.

On a hierarchicalSchema engine the tree already lists every schema and keys each object list by an explicit schema, so neither the schema list nor the per-schema tables can go stale. Only the routines can: PluginDriverAdapter.fetchProcedures resolves a nil schema to the driver's current one. The switch now re-reads only the routines and the autocomplete namespaces.

Verification

Run through .claude/skills/fix-issue/scripts/verify.sh against this branch's worktree:

  • build: PASS
  • test (12 suites: container switch planning and routing, drop eligibility, container entity names, database switching, database tree capability/selection/nodes, scoped driver routing, schema-change routing, quick switcher, export models): 165 executed, 165 passed, 0 failed
  • swiftlint lint --strict over the app and the changed test files: clean
  • docs reference check: clean

New tests: SchemaOnlyContainerRoutingTests composes each engine's declared capabilities with the planner and pins that a table click on Dameng, Oracle and BigQuery plans only a schema, that Elasticsearch and etcd plan nothing, that Redis still declares no dimension while keeping its numbered-database switching, and that PostgreSQL and MSSQL still switch both dimensions database-first. ContainerSwitchPlannerTests gains the no-database cases. ContainerDropEligibilityTests gains a nil-database case for the now-optional type.

Not covered by automation

No TableProUITests case. Reproducing the alert needs a live Dameng, Elasticsearch or etcd server, so it would not run deterministically in CI.

No before/after screenshots. The visible change is the absence of a modal alert, and capturing the "before" state needs one of those live servers, which I do not have here. The alert's exact contents are in the issue's final comment.

Review

/code-review high raised three findings against this diff and all three were correct and are fixed here:

  1. Filtering the schema step against a session snapshot taken before the database switch dropped a needed schema switch on .bySchema engines. The skip now happens per step against the live session, and the planner overload that invited the mistake is gone.
  2. The lighter schema-switch refresh left loadedScope naming the schema the session had left, so the next reader compared the two and ran the full reload it was meant to avoid. It now records the scope it covers.
  3. A CHANGELOG bullet claimed a drop-eligibility fix that is not reachable in production. Removed.

@mintlify

mintlify Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
TablePro 🟢 Ready View Preview Aug 20, 2026, 7:20 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@datlechin
datlechin merged commit fe6e0a2 into main Aug 20, 2026
3 checks passed
@datlechin
datlechin deleted the fix/schema-only-container-switch branch August 20, 2026 07:20
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.

dameng bugs

1 participant