File tree Expand file tree Collapse file tree
packages/plugins/policy/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -920,6 +920,10 @@ export class PolicyHandler<Schema extends SchemaDef> extends OperationNodeTransf
920920 for ( let i = 0 ; i < data . length ; i ++ ) {
921921 const item = data [ i ] ! ;
922922 if ( typeof item === 'object' && item && 'kind' in item ) {
923+ if ( item . kind === 'DefaultInsertValueNode' ) {
924+ result . push ( { node : ValueNode . create ( null ) , raw : null } ) ;
925+ continue ;
926+ }
923927 const fieldDef = QueryUtils . requireField ( this . client . $schema , model , fields [ i ] ! ) ;
924928 invariant ( item . kind === 'ValueNode' , 'expecting a ValueNode' ) ;
925929 result . push ( {
Original file line number Diff line number Diff line change 1+ import { createPolicyTestClient } from '@zenstackhq/testtools' ;
2+ import { describe , expect , it } from 'vitest' ;
3+
4+ // createManyAndReturn fails with "Invariant failed: expecting a ValueNode"
5+ // when rows in the batch have asymmetric columns (one row provides a field the other omits)
6+ describe ( 'Regression for issue #2460' , ( ) => {
7+ it ( 'createManyAndReturn with asymmetric optional fields across rows' , async ( ) => {
8+ const db = await createPolicyTestClient (
9+ `
10+ model User {
11+ id Int @id @default(autoincrement())
12+ role String
13+ @@allow('all', true)
14+ }
15+
16+ model Item {
17+ id Int @id @default(autoincrement())
18+ key String
19+ note String?
20+ @@allow('all', auth().role == 'admin')
21+ }
22+ ` ,
23+ { provider : 'postgresql' } ,
24+ ) ;
25+
26+ const user = await db . user . create ( { data : { role : 'admin' } } ) ;
27+
28+ const result = await db . $setAuth ( user ) . item . createManyAndReturn ( {
29+ data : [
30+ { key : 'a' , note : 'hello' } ,
31+ { key : 'b' } ,
32+ ] ,
33+ } ) ;
34+
35+ expect ( result ) . toHaveLength ( 2 ) ;
36+ } ) ;
37+ } ) ;
You can’t perform that action at this time.
0 commit comments