fix(service-analytics): executeRawSql 桥接透传 objectName —— dataset 原始 SQL 打回对象自己的 datasource (#5033) - #5119
Merged
Conversation
… the default datasource (#5033) `AnalyticsServicePlugin`'s `executeRawSql` auto-bridge received the object name and dropped it: `engine.execute(knexSql, { args: params })`. `ObjectQL.execute()` selects its driver in the order `options.object` -> `getDriver(object)`, then `options.datasource`, then the default driver, so rule 1 could never fire and every dataset raw-SQL read landed on the DEFAULT datasource. Any object routed elsewhere (ADR-0057 3.6 telemetry split, an explicit `object.datasource`, a `datasourceMapping` rule) raised `no such table`, which the widget-level graceful degradation turned into a confident `0` over live rows. Measured on the showcase: `sys_audit_log` returned 49 records object-routed and `{"rows":[]}` through the dataset raw-SQL path, on one running kernel. The bridge now passes `{ args: params, object: objectName }`, matching the `executeAggregate` bridge beside it, so both dataset execution paths give one answer to "which datasource is this object in". `DataEngineLike.execute`'s options bag is spelled out instead of `Record<string, unknown>` so the load-bearing key is visible at the call site. Accepted behaviour change: a dataset whose SQL joins across datasources now runs on the base object's own datasource and fails there rather than silently reading the wrong database. It must fail as ITSELF -- reporting it as "backing object is unavailable" would keep the confident `0` alive under a new cause -- so the missing-source triage now asks WHICH relation the driver named: - the dataset's own object -> degrade to an empty result + WARN (unchanged) - a joined table whose object -> degrade (genuine absence, unchanged shape) is not registered here - a joined table whose object -> throw, naming table X, the datasource its IS registered base object lives on, where X actually is, and the remedy `AnalyticsServiceConfig` gains one optional diagnostics-only hook, `getObjectDatasource(objectName)`, wired in `plugin.ts` from the engine's schema registry. It never selects a driver. Tests: `src/__tests__/raw-sql-object-routing.test.ts` drives the real plugin wiring against an engine double that resolves its driver the way `execute()` documents -- the defect was invisible to every test that stubbed `executeRawSql` directly. Covers the issue's exact shape (raw SQL == object-routed rows, no degradation WARN), default-datasource objects unchanged, the cross-datasource loud failure and its wording, and both surviving degradation paths. Compile-time rejection of cross-datasource dataset joins is deliberately not in this PR; filed as #5115. Fixes #5033 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NrmBxj8rK2uGCnh9aipjwX
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 8 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
xuyushun441-sys
marked this pull request as ready for review
August 4, 2026 05:29
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 #5033
结论
AnalyticsServicePlugin的executeRawSql自动桥接收到了对象名却把它丢掉了 ——engine.execute(knexSql, { args: params })。ObjectQL.execute()的驱动选择顺序是options.object→getDriver(object),其次options.datasource,最后默认驱动;第 1 条永远走不到,于是每一次 dataset 原始 SQL 读都打在默认 datasource 上。凡被路由到别处的对象(ADR-0057 §3.6 telemetry 拆分、显式object.datasource、datasourceMapping规则)都读到no such table,再被 widget 层的优雅降级换成一个自信的0—— 而底下是真实存在的行。桥接现在传
{ args: params, object: objectName },与同文件里一直路由正确的executeAggregate(engine.aggregate(objectName, …))同姿态。两条 dataset 执行路径从此对「这个对象在哪个库里」给同一个答案,选中哪条策略不再决定你读到的是数据还是零。顺带把
DataEngineLike.execute的 options 从Record< string, unknown >展开成具名的{ args?, object? }:这个键是承重的,应该在调用点就看得见,而不是藏在一个什么都收的索引签名里。⛔
packages/spec/**与生成物零改动 ——engine.execute的契约本来就声明了object优先级(见packages/objectql/src/engine.ts的execute()注释),本单只是把丢掉路由键的那个消费者修回声明,不需要动契约。packages/objectql/**只读未改;metadata-protocol/src/protocol.ts未触碰;content/docs/releases/未触碰。已接受的行为变更:跨 datasource 的 dataset JOIN 现在响亮失败
NativeSQLStrategy为点号维度(account.region)生成LEFT JOIN。语句现在跑在基对象自己的 datasource 上,join 目标要是不在那个库里,就会在那里失败 —— 而不再像以前那样静默读错库。这是对的(fail-loud),但它必须以自己的身份失败:如果继续报「backing object … is unavailable」并返回空结果,那就是换了个原因让同一个自信的0活下来,而且基表明明就在那儿。所以缺表分诊现在问的是「驱动指名的是哪张表」:
第三行的实际文案:
AnalyticsServiceConfig为此新增一个仅用于诊断的可选钩子getObjectDatasource(objectName),由plugin.ts从 engine 的 schema registry 接出。它不参与任何驱动选择。测试
新增
packages/services/service-analytics/src/__tests__/raw-sql-object-routing.test.ts,沿用execution-context-bridge.test.ts立下的fakePluginContext惯例,驱动真实的 plugin 装配,对着一个「按execute()文档的顺序解析驱动」的 engine double 跑 —— 这个缺陷对每一个直接 stubexecuteRawSql的测试都是不可见的,这也是它活到现在的原因。9 个用例:
object交给engine.execute(驱动选择的第一把钥匙);is unavailableWARN);本地闸门
@objectstack/service-analytics的 patch 级 changeset 已随本 PR 提交(.changeset/analytics-raw-sql-object-routing.md),内含上面那条行为变更的说明与迁移指引。范围外发现
🤖 Generated with Claude Code
https://claude.ai/code/session_01NrmBxj8rK2uGCnh9aipjwX
Generated by Claude Code