Skip to content

assertSortFieldsExist's dotted-path SORT hint also prescribes an unmaterializable "formula or rollup" denormalization — same defect class as #6673, different axis #6924

Description

@os-project-manager

Split out of #6673 while verifying its premise (comment: #6673 (comment)). Recorded, not claimed.

What #6673 actually found vs. what this is

#6673 fixed two packages/lint hints that told authors to mirror a related record's value onto a formula field for searchableFields — a fix that can't work because a formula field is virtual (no driver materializes a column for it) and CEL only reads the record's own fields.

While re-verifying #6673's third named target (protocol.ts:4780, claimed to be inside assertSearchFieldsAreSearchable), I found that text actually lives in a different function: assertSortFieldsExist (packages/metadata-protocol/src/protocol.ts:4745), guarding the SORT axis (#4226/#4256), not searchableFields/#4254 at all.

The text, and why it may be the same defect

protocol.ts:4780 (in assertSortFieldsExist, for a dotted-path orderBy like ?sort=account.company_name):

hint: ` Denormalise the value onto '${object}' (a formula or rollup field that`
    + ' copies it into a real column) and sort by that.',

This claims a formula/rollup(summary) field "copies it into a real column". By the same argument #6673 already established for formula: it's virtual, no driver materializes a column for it (packages/objectql/src/engine.ts:568-573 computes it post-query, in-memory; driver-sql/src/schema-drift.ts; driver-turso/src/remote-transport.ts). summary/rollup fields are likewise excluded from real-column treatment elsewhere in this same file (the clone copy-exclusion at protocol.ts:5941, "computed formula/summary fields"). So ORDER BY <formula-or-rollup-field> looks structurally like it should hit the exact same silent-degradation path #3821's backstop already covers for other unknown-column ORDER BYs: query succeeds, rows are all there, order is arbitrary — the very failure mode #4226/#4256 exist to stop.

Not independently reproduced — I didn't run a live repro (formula field named directly, non-dotted, in orderBy) proving the driver silently drops the sort; this is inferred from the codebase architecture (post-query formula evaluation, the #3821 backstop, the summary/rollup copy-exclusion), not measured. Flagging for someone to verify before dispatch.

Why this is not simply "the same fix"

Scope if promoted

Needs a decision first, not just a rewording: is "denormalise onto formula/rollup and sort by that" actually broken (verify with a real repro — plain non-dotted orderBy naming a formula-typed field, check whether it silently drops the sort or throws), and if so, what's the right prescription (a stored/mirrored field, same as #6673's fix) — touching protocol.ts (assertSortFieldsExist), its pinned test in packages/objectql, and the still-current doc at query-syntax.mdx:533-534 together, so code and docs move in the same PR this time.

Refs: #6673, #4256 (the SORT-axis dotted-path decision, closed), #4226, #3821.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions