3636 * the bare foreign key when a sub-read throws, so the refusal would reach the
3737 * caller as a silently unexpanded field. Judged here, before the parent read,
3838 * it reaches the caller as a refusal.
39+ *
40+ * ## A projection emptied by the unknown-column tolerance
41+ *
42+ * [#27165] `find` / `findOne` drop a requested plain column the object does not
43+ * have (the #7589 tolerance). When that leaves nothing, the projection is
44+ * empty, and it gets this same refusal, naming what was asked for. Before, the
45+ * engine fell back to every column there, so `fields: ['nope']` answered wider
46+ * than any named projection. A mix of known and unknown columns keeps the
47+ * tolerance. An `expand` entry needs no judgement of its own here: its
48+ * sub-read always names `id`, which is never dropped.
3949 */
4050
4151import { EngineQueryOptionsSchema } from '@objectstack/spec/data' ;
@@ -48,9 +58,17 @@ function projectionNamesNoField(): string | undefined {
4858 return declaredRefusal ;
4959}
5060
51- function refuseEmptyProjection ( object : string , operation : 'find' | 'findOne' , param : string ) : never {
61+ function refuseEmptyProjection (
62+ object : string ,
63+ operation : 'find' | 'findOne' ,
64+ param : string ,
65+ requested : readonly unknown [ ] = [ ] ,
66+ ) : never {
67+ const dropped = requested . length > 0
68+ ? `, and none of them is a field of '${ object } ' (an unknown column is dropped from a projection)`
69+ : '' ;
5270 const err : any = new Error (
53- `ObjectQL.${ operation } ('${ object } ') names no field in ${ param } : got [] . The query was not run: `
71+ `ObjectQL.${ operation } ('${ object } ') names no field in ${ param } : got ${ JSON . stringify ( requested ) } ${ dropped } . The query was not run: `
5472 + 'an empty projection was read as no projection, which answers every column. '
5573 + `${ projectionNamesNoField ( ) } , or leave the projection out to read every column.` ,
5674 ) ;
@@ -93,3 +111,16 @@ export function assertProjectionNamesAField(
93111 if ( Array . isArray ( query . fields ) && query . fields . length === 0 ) refuseEmptyProjection ( object , operation , "'fields'" ) ;
94112 assertExpandProjections ( object , operation , query . expand , '' ) ;
95113}
114+
115+ /**
116+ * [#27165] Refuse a projection the unknown-column tolerance emptied: every
117+ * entry of `requested` named a column `object` does not have. Same refusal as
118+ * `fields: []`, naming what was asked for.
119+ */
120+ export function refuseProjectionOfUnknownColumns (
121+ object : string ,
122+ operation : 'find' | 'findOne' ,
123+ requested : readonly unknown [ ] ,
124+ ) : never {
125+ return refuseEmptyProjection ( object , operation , "'fields'" , requested ) ;
126+ }
0 commit comments