Repository navigation
fix(lint, service-analytics): a total over a formula field names the stored-number remedy, not a count - #24505
Conversation
…tal over a formula field The measure-aggregate-field-type-refused hint for sum/avg/min/max over a formula steered the author to count / count_distinct. The spec now owns the one prescription (virtualFieldAggregateRemedy): store the value as a number field and aggregate that, with a count named only as a different question. The lint hint, its os explain entry and the dataset compile leg all read it. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D6F9axfoPzR7t8G1J7Ytzz
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D6F9axfoPzR7t8G1J7Ytzz
… export Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D6F9axfoPzR7t8G1J7Ytzz
…asure-total-hint-stored-number
📓 Docs Drift Check5 anchor(s) derived from 3 changed package(s); no hand-written page names any of them. What this run could not see
Coarse fallback — 143 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 89482353059d5d92f409a36095f3f9f959d5a0cb && git checkout 89482353059d5d92f409a36095f3f9f959d5a0cb
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 7e58e0a27998194640c145344b7519f1ccc9fad4 3ecaba7595e05f1e303ecd7ce5af27a0174586ca && git checkout -B drift-repro 7e58e0a27998194640c145344b7519f1ccc9fad4 && git merge --no-ff 3ecaba7595e05f1e303ecd7ce5af27a0174586ca
node scripts/docs-audit/affected-docs.mjs --json 7e58e0a27998194640c145344b7519f1ccc9fad4 |
Review: ACCEPT · PR #24505 @
|
Fixes #24426
Clause-②: no
What changed
A dataset measure (or an authored cube measure) that takes
sum/avg/min/maxover aformulafield is still refused. Only the prescription changed. It used to name a count as the way out:A count read as a total is the plausible wrong number from objectstack-ai/cloud#2861: "Total Leave Days" showed 3 records against a true total of 10 days. The hint now gives the spec's remedy first and names the count only as a different question:
One source
@objectstack/spec/data, inaggregate-field-type-compatibility.ts(the table module). It exportsVIRTUAL_FIELD_AGGREGATE_REMEDY(the sentence) andvirtualFieldAggregateRemedy(aggregate, fieldType). The function returns the sentence for a REFUSEDsum/avg/min/maxover a type inSEARCH_VIRTUAL_TYPES(todayformula, the drivers' storage rule). It returnsundefinedfor every other pair. Like the predicate, it fails closed on non-string input. The class is not a new list: it reusesSEARCH_VIRTUAL_TYPES, and a spec test holds every member refused on all four value-reading rows.isAggregateCompatibleWithFieldType,AGGREGATE_FIELD_TYPE_COMPATIBILITY). Its TSDoc is where the module says formula is refused because it is virtual. An extra export in amigrations/entries/semantic/*.tsfile would sit inside the generated-registry tree, which holdsSemanticMigrationentries only. Dependency direction checked:@objectstack/lintand@objectstack/service-analyticsboth list@objectstack/specasworkspace:*. Spec imports neither of them.measure-aggregate-field-type-refusedhint (validate-dataset-measure-aggregates.ts, dataset and cube legs);REMEDY_BY_SOURCE_CLASS(dataset-compiler.ts), which now asks the spec first;os explain measure-aggregate-field-type-refused(rule-explanations.ts, that entry only). This module imports nothing by design, so the entry writes the sentence out and a lint test holds it equal to the constant. I also dropped "(a computed column)" from the existing stored-numeric sentence, because a formula IS a computed column, so that wording pointed the reader the wrong way.count_distinctover a JSON-stored type and over amultiple: truedeclaration ("… declaration accepts: count."), the temporal sentence, the min/max sort sentence, and the non-numeric sentence. No pair moved between accepted and refused.Tests (at
3ecaba7595, after mergingorigin/main, which already contains #24474)@objectstack/lintvalidate-dataset-measure-aggregates.test.ts. New describe block:sumover a formula: hint=== VIRTUAL_FIELD_AGGREGATE_REMEDY, contains "store the value as a number field", the remedy comes before thecountmention, and no "accepts: count";avg/min/maxread the same sentence;os explaincontains the sentence verbatim;sum×textkeeps "type accepts: count, count_distinct.",count_distinct×selectmultiple: truekeeps "declaration accepts: count.",count_distinct×jsonkeeps "type accepts: count.", andcount× formula fires nothing.fix:line pin now covers the formula hint too.@objectstack/service-analyticsaggregate-nontemporal-measure-refusal.test.ts:sum/avg/min/max×formulagivesDATASET_INVALID/ 400 with no SQL emitted, and the message contains the spec sentence and neither the non-numeric nor the sort sentence. Control:sum×textkeeps "For a non-numeric field".@objectstack/specaggregate-field-type-compatibility.test.ts: the four aggregates over formula return the sentence,undefinedeverywhere else (accepted pairs and stored classes), fail-closed shape cases, one line of at most 200 characters, and the virtual class refused on all four rows.Package runs
3ecaba7595(merged head):@objectstack/specpnpm test, 699 files / 21281 passed; spectest:repowas run before the merge, 70 files / 1162 passed; the three targeted files above, 76 + 49 + 28 passed.b3a054b0afplus its changeset and regen commits):@objectstack/lintpnpm test, 145 files / 6870 passed;@objectstack/service-analyticspnpm test, 183 files / 4498 passed, 262 skipped;typecheckgreen for lint, service-analytics and spec.node scripts/pm/dispatch-gates.mjs --commandsat3ecaba7595derived 91 commands. All 91 were run, every one exited 0, and--ranreports 91 run, 0 NOT-MEASURED, 0 UNRUN.check:api-surfaceandcheck:export-originswent red on the new export as expected and were regenerated (gen:api-surface,gen:export-origins): two added names, nothing removed.Reverse verification (fix committed first;
scripts/ablation-replace.mjs, which restores to HEAD and checksgit diff HEADis empty)virtualFieldAggregateRemedy(aggregate, fieldType) ??(anchor 1 → 0, blob e0f84182c232 → cd6b974fa3a7). Two lint cases went red with Received "Either point "sum" at a field of an accepted type, or aggregate "measured" with one itsformulatype accepts: count, count_distinct." The explain-equality case stayed green, as expected: that text does not depend on the line. Restored: blob == HEAD.if (virtual !== undefined) return virtual;(blob 170605d63191 → 68caccc65865). The new compile case went red with the old "For a non-numeric field,countaccepts every type …" remedy. Restored: blob == HEAD.src/by relative path, so the ablations needed nodist/rebuild.Acceptance notes
service-analytics/src/cube-measure-field-type-door.ts, "… aggregate a field of one of those types, or count the rows with count.",400 INVALID_FIELD) and the engine'saggregatedoor (objectql/src/aggregate-field-type-door.ts, the same clause). Both can readvirtualFieldAggregateRemedythe same way. Reported for the seat to place; not measured over HTTP in this run.formulacolumn …". The lint message says the same thing ("the number would depend on the SQL dialect"). For a virtual field the real reason is that no column exists. The wording is inaccurate but not misdirecting, since the remedy line now names the fix. Noted only.count_distinct×formula. The table accepts it, and the shared sentence names it as "a different question". Whether every backend can actually lower acount_distinctover a column that is never emitted is not measured here.Generated by Claude Code