fix(coordinator): resolve a table tab's schema from the active session when none is given#1808
Conversation
…n when none is given (#1774)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b81f9a6f9e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let resolvedSchemaName = DatabaseManager.shared.resolvedSchemaName( | ||
| payload.schemaName, for: connectionId | ||
| ) |
There was a problem hiding this comment.
Resolve schema after switching to the payload database
When a table payload such as MCP open_table_tab provides a databaseName different from the live session and omits schemaName, this resolves nil against the pre-switch session schema. initializeAndRestoreTabs later switches to selectedTab.tableContext.databaseName, but the tab has already been stamped and its query built with the old schema, so opening db_b.users while the session is on db_a.sales can query db_b.sales.users instead of the target database's default/current schema. Defer this fallback until after the database switch, or skip it when the payload database is not the active database.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| private func consumePendingLoad(trigger: TableLoadTrigger, session: ConnectionSession) { |
There was a problem hiding this comment.
Stamp restored tab schemas after the database switch
When a pending load resumes for a restored nil-schema table whose saved database differs from the connected session, this call stamps the schema before the code below switches to the tab's database. After the switch, lazyLoadCurrentTabIfNeeded sees a non-nil schema and prepareTableTabFirstLoad will not re-resolve it, so the first query is qualified with the schema from the previous database. Move the schema resolution after the database switch so legacy restored tabs use the schema for their own database.
Useful? React with 👍 / 👎.
Summary
DatabaseManager.resolvedSchemaName(_:for:); explicit schemas always win, schema-less engines stay nil.open_table_tabtool, and tabs restored from either. FK navigation now uses the same resolver (no behavior change there).FilterSQLGenerator.generatePreviewSQL.Root cause
Quick Switcher items and MCP payloads carry no schema, so
tableContext.schemaNamestayed nil. Query builders correctly refuse to guess, so SQL Server received unqualified names: SELECT resolved through the login default schema and failed with "Invalid object name", and generated INSERT/UPDATE/DELETE could silently target a same-named table in another schema. No rebuild ever fixed the write path.The sidebar path was already fixed by #1758. The re-report in #1774 came from the registry serving the pre-fix MSSQL plugin binary until v1.0.29 was published on June 30. This PR fixes the remaining nil-schema paths app-side; no plugin re-release is needed.
The fix deliberately does not add a
_currentSchemafallback inside the driver (the approach in #1778): SQL Server has no session schema, and the app's cached query-building driver never connects, so its_currentSchemais permanentlydboand would mis-qualify names for logins with a different default schema.Related: #1774. Supersedes #1778.
Validation
xcodebuild teston the six affected suites: 131 passed, 0 failed, including 13 new tests (Quick Switcher and MCP payload reproductions, resolver unit tests, first-load backstop, FK regression guard)swiftlint lint --stricton changed files: no new violationsgit diff --cachedstyle gate: clean