fix(analytics): fall back to aggregate strategy when the driver can't run SQL#1701
Merged
Merged
Conversation
… run SQL Every dataset query on an in-memory-driver environment returned rows:[] with HTTP 200 and the compiled SQL attached — dashboards read "No rows" forever while looking healthy (live staging incident: even COUNT(*) FROM sys_user and queries against nonexistent tables came back empty). Root cause chain: InMemoryDriver.execute() returns null for raw SQL; the analytics plugin's auto-bridge mapped null to [] silently; and the default queryCapabilities unconditionally advertise nativeSql, so NativeSQLStrategy was always selected even on drivers that cannot execute SQL. Fix at both layers: - the raw-SQL bridge now throws a TYPED error (code RAW_SQL_UNSUPPORTED) when the engine returns null/undefined — an empty result is never fabricated; - AnalyticsService.query treats that error as a runtime capability miss and falls back to the next capable strategy (ObjectQLStrategy over the aggregate bridge — the in-memory driver implements aggregate()), skipping the proven-incapable one. Any other error propagates untouched, and when no fallback exists the failure is loud and names the skipped strategies. service-analytics: 109 tests green (3 new covering fallback, error passthrough, and the no-fallback loud failure). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Jun 11, 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.
The bug (live on staging)
Every dataset query on staging tenant environments returned
rows: []with HTTP 200 and the compiled SQL attached — all dashboards read "No rows" forever while looking healthy. EvenCOUNT(*) FROM sys_userand queries against nonexistent tables came back empty (the discriminating probe).Root cause chain
execute()logs a warning and returnsnullfor raw SQL (memory-driver.ts:250).null→[].queryCapabilitiesunconditionally advertisenativeSql: true(the bridge closure always exists), soNativeSQLStrategywas selected on a driver that cannot execute SQL — compiled SQL attached, never executed.Fix (both layers)
null/undefinedfromengine.executenow throws a typedRAW_SQL_UNSUPPORTEDerror — an empty result is never fabricated.AnalyticsService.querytreats that error as a runtime capability miss and falls back to the next capable strategy —ObjectQLStrategyover the aggregate bridge (the in-memory driver implementsaggregate()), so memory-backed environments now return real numbers. Any other error propagates untouched; with no fallback available the failure is loud and names the skipped strategies.Test
service-analytics 109 green — 3 new: fallback returns the aggregate rows; non-typed errors propagate without fallback masking; no-fallback case fails loudly (never silent
[]).Staging validation follows via the cloud
.framework-shabump.🤖 Generated with Claude Code