Repository navigation
fix(sidebar): stop asking an engine with no databases to switch one - #2286
Merged
Merged
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Signed-off-by: Ngô Quốc Đạt <[email protected]>
This was referenced Aug 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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".
browsingDatabasemaps an empty browse database tonil, and then three node-construction sites undo that with?? ""and store it in a non-optionalDatabaseTreeTableRef.database. Every consumer compares that against anactiveDatabasethat is nil-flattened. Swift promotes the left side, so("" as String) != (nil as String?)istrue, always.activate(_:)therefore firedswitchDatabase(to: "")on every single table click.2. The database-vs-schema decision was duplicated instead of centralized.
switchableContainers->ContainerSwitchPlanneris the intended chokepoint, and onlyswitchContainerand the deep-link path used it. The sidebar tree, the tab-restore path andDatabaseManager.switchDatabaseeach decided for themselves, so nothing stopped a database switch on an engine that has no databases. The call reached the PluginKit defaultswitchDatabase(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 aliasesswitchDatabasetoswitchSchemawith the comment "Aliases to keepcoordinator.switchDatabaseworking 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.databaseis 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.ContainerDropEligibilitycompares 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.databaseis 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.databaseandDatabaseContainerRef.databaseareString?. The""sentinel no longer exists. Every other consumer of that comparison turned out to be safe today, each for its own local reason (a== nilshort 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 throughContainerSwitchPlanner..bySchemaengine, switching database callsresetSchemaand moves the session to the engine's default schema, so a schema filtered out as redundant beforehand would leave the session ondbo. This preserves the redundant-schema skipactivate(_:)had and the link path never did.fetchDatabases()with their schema list, so the switcher showed every schema twice and the copy labelled "Database" failed with the same driver error.DatabaseManager.switchDatabaserefuses an empty name rather than passing it to the driver.Deliberately not gated on
supportsDatabaseSwitching: Redis declares that flagfalseand still issues a realSELECT n, and Oracle aliases to a schema switch. The dimension rule isswitchableContainers == [.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 serialfetchTables(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 holdssessionDriverGate.withExclusiveAccesswhile the clicked table's own SELECT waits behind it. Every expanded schema added a round trip to one click.On a
hierarchicalSchemaengine 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.fetchProceduresresolves 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.shagainst this branch's worktree:build: PASStest(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 failedswiftlint lint --strictover the app and the changed test files: cleanNew tests:
SchemaOnlyContainerRoutingTestscomposes 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.ContainerSwitchPlannerTestsgains the no-database cases.ContainerDropEligibilityTestsgains a nil-database case for the now-optional type.Not covered by automation
No
TableProUITestscase. 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 highraised three findings against this diff and all three were correct and are fixed here:.bySchemaengines. The skip now happens per step against the live session, and the planner overload that invited the mistake is gone.loadedScopenaming 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.