Skip to content

Commit 4f3a5cc

Browse files
committed
test(objectql): the pins of the old fallback now expect the refusal; add the changeset
Claude-Session: https://claude.ai/code/session_01L6bhgXcN9HaZYSEUdJWEjw Co-authored-by: Claude <noreply@anthropic.com>
1 parent 88d7f78 commit 4f3a5cc

3 files changed

Lines changed: 35 additions & 13 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/objectql': patch
3+
---
4+
5+
fix(objectql)!: the in-process engine refuses a projection whose every column is unknown, as it refuses an empty one (#27165)
6+
7+
Clause-②: no (narrowing) — `ObjectQL.find` / `findOne` refuse a `fields` list naming only columns the object does not have, which they read before as every column. Nothing is widened.
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export or type changes: the engine already refused an empty projection, and a projection that its unknown-column tolerance empties is now judged the same way. There is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** accept-set narrowing at the in-process read entry (`@objectstack/objectql`).
13+
14+
- **Before.** `find` / `findOne` drop a requested plain column the object does not have. When that left nothing, they fell back to every column: `engine.find(object, { fields: ['nope'] })` answered every column, owner, organization and audit columns included, and the caller was not told. The REST door refuses the same request.
15+
- **Now.** That case is an empty projection and gets the empty projection's refusal, before any driver read: `status: 400`, `code: 'VALIDATION_ERROR'`, the declaration's words (`Name at least one field`), and the message names the columns that were asked for.
16+
- **Unchanged.** A mix of known and unknown columns still projects the known ones and drops the rest. An absent or `null` `fields` still reads every column. A host whose object has no registered field map is not judged.
17+
- **Who sees it.** A plugin, hook, flow or other in-process caller whose projection names only columns the object lacks, for example a typo or a column from another object. No in-repo caller does.
18+
19+
**The remedy.** Name at least one column the object has, or leave `fields` out to read every column.

‎packages/objectql/src/query-expression-conformance.test.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,14 +1783,17 @@ describe('#4226 — sort / select / expand on the list path (real ObjectQL engin
17831783
for (const r of rows) expect(Object.keys(r).sort()).toEqual(['title']);
17841784
});
17851785

1786-
it('[#7589 GUARD] a projection of ONLY unknown plain columns still falls back to every field', async () => {
1787-
// The `SELECT *` fallback itself, pinned as KEPT for the plain case:
1788-
// this is the documented tolerance the ruling preserves, not a defect
1789-
// this card missed. (The DOTTED route into this same fallback is what
1790-
// was closed above.)
1791-
const rows: any[] = await engine.find('showcase_task', { fields: ['no_such_field'] });
1792-
expect(rows).toHaveLength(5);
1793-
expect(Object.keys(rows[0])).toEqual(expect.arrayContaining(['id', 'title', 'status']));
1786+
it('[#27165] a projection of ONLY unknown plain columns is an empty projection, refused', async () => {
1787+
// The `SELECT *` fallback this guard pinned as KEPT is closed by its
1788+
// own ruling (#27165 triage): a projection the tolerance empties is an
1789+
// empty projection, refused as `fields: []` is (#27008), never read as
1790+
// every column. The tolerance itself stays for a mixed projection
1791+
// (the guard above).
1792+
const err: any = await engine
1793+
.find('showcase_task', { fields: ['no_such_field'] })
1794+
.then(() => null, (e: unknown) => e);
1795+
expect(err).toMatchObject({ status: 400, code: 'VALIDATION_ERROR' });
1796+
expect(err.message).toMatch(/names no field in 'fields': got \["no_such_field"\]/);
17941797
});
17951798

17961799
it('[#7589 GUARD] `engine.findOne` keeps the same plain tolerance', async () => {

‎packages/objectql/src/unprojected-read-declared-fields-conformance.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ describe.each<Behaviour>(['whole row', 'projection', 'ladder'])(
203203
});
204204

205205
it('door: an explicit projection naming ONLY a retired column', async () => {
206-
// The engine's unknown-plain tolerance drops the name and reads the
207-
// default projection; it must not read every column.
208-
const rows = await h.engine.find(CONTACT, { fields: ['mailing_street'] });
209-
expect(rows[0]).toMatchObject({ id: 'con_1', name: 'Ada' });
210-
expectNoRetiredColumn(rows);
206+
// The engine's unknown-plain tolerance drops the name, which leaves an
207+
// empty projection: [#27165] refused, as `fields: []` is, so the
208+
// retired column is never read and no row is served.
209+
const err: any = await h.engine.find(CONTACT, { fields: ['mailing_street'] }).then(() => null, (e: unknown) => e);
210+
expect(err).toMatchObject({ status: 400, code: 'VALIDATION_ERROR' });
211211
});
212212

213213
it('door: expand — the related record is the related object\'s declared fields', async () => {

0 commit comments

Comments
 (0)