Skip to content

Commit ef52884

Browse files
huangyiireneclaude
andauthored
fix(driver-sql): aggregate() attributes an unresolvable column to its clause (#11729)
* fix(driver-sql): attribute an unresolvable aggregate column to its clause aggregate() answered DATABASE_ERROR/500 for an unresolvable column where find() and count() answer the #8790 refusal. The dialect-named column is now attributed to the clause the caller's own query names it in: a groupBy field or an aggregation field refuses INVALID_FIELD/400 (the ingress door's own code for this condition), a column in neither clause is the WHERE and keeps the #8790 INVALID_FILTER/400 refusal verbatim, and a wording that parses to no name keeps the #11455 terminal envelope unchanged (no supportable attribution, per the #8931 ruling). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VK8rFDtg8eREaxBGX99Csn * test(driver-sql): type the groupBy spelling loop without a readonly cast Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VK8rFDtg8eREaxBGX99Csn --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5383fa6 commit ef52884

4 files changed

Lines changed: 644 additions & 17 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@objectstack/driver-sql": patch
3+
---
4+
5+
`aggregate()` now answers an unresolvable column with the same refusal class as `find()` and `count()` instead of the generic `DATABASE_ERROR`/500 terminal — the #8790 refusal reaching the third read door (#11541). The dialect-named column is attributed to the clause the caller's own query names it in: a `groupBy` field or an aggregation `field` refuses with `INVALID_FIELD`/400 naming the column and the clause (the same code the protocol ingress gives this condition, #4254); a column named by neither clause is the WHERE, which answers #8790's `INVALID_FILTER`/400 refusal verbatim; a dialect wording that yields no column name keeps the #11455 terminal envelope unchanged, because no attribution is supportable there (#8931). Drivers extending `SqlDriver` (`driver-turso`'s embedded face, `driver-sqlite-wasm`) inherit the same answers.

packages/drivers/driver-sql/src/sql-driver-11455-aggregate-fault-envelope.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@
7474
*
7575
* ## What is deliberately NOT here
7676
*
77-
* ⛔ No `isUnresolvableColumnError` arm, unlike `count()`. That refusal's words
78-
* are *"Filter on 'x' names a column that object 'o' has no column for"*, and
79-
* this door names columns in THREE clauses — the WHERE, the `groupBy` fields
80-
* and the aggregation `field`. A blanket arm would tell the author of
81-
* `avg('nosuchcol')` that their FILTER was wrong. Filed as its own card rather
82-
* than guessed at here; see the note on `SqlDriver.aggregate`.
77+
* ⛔ No BLANKET `isUnresolvableColumnError` arm, unlike `count()`. That
78+
* refusal's words are *"Filter on 'x' names a column that object 'o' has no
79+
* column for"*, and this door names columns in THREE clauses — the WHERE, the
80+
* `groupBy` fields and the aggregation `field`. A blanket arm would tell the
81+
* author of `avg('nosuchcol')` that their FILTER was wrong. This suite left
82+
* the gap FILED rather than guessed at; #11541 has since closed it with a
83+
* clause-attributing classifier (`SqlDriver.aggregateBackendFault`, pinned by
84+
* `sql-driver-11541-aggregate-unresolvable-column-refusal.test.ts`). What this
85+
* suite pins is unchanged by that: an error the classifier does NOT claim — a
86+
* missing table, a `42883` function fault, a wording no dialect parser reads —
87+
* still leaves as this terminal envelope, never as a clause verdict.
8388
*/
8489

8590
import { describe, it, expect, beforeAll, afterAll } from 'vitest';

0 commit comments

Comments
 (0)