Skip to content

Commit 9076fe6

Browse files
pkudinovclaude
andcommitted
fix(policy): handle DefaultInsertValueNode in createManyAndReturn
When rows have asymmetric optional fields, Kysely pads missing columns with DefaultInsertValueNode. Treat it as null in the policy handler. Fixes #2460 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e01736f commit 9076fe6

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

packages/plugins/policy/src/policy-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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({

tests/regression/test/issue-2460.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ describe('Regression for issue #2460', () => {
77
it('createManyAndReturn with asymmetric optional fields across rows', async () => {
88
const db = await createPolicyTestClient(
99
`
10-
type AuthUser {
11-
id String
10+
model User {
11+
id Int @id @default(autoincrement())
1212
role String
13-
@@auth
13+
@@allow('all', true)
1414
}
1515
1616
model Item {
@@ -20,13 +20,12 @@ model Item {
2020
@@allow('all', auth().role == 'admin')
2121
}
2222
`,
23-
{
24-
provider: 'postgresql',
25-
auth: { id: '1', role: 'admin' },
26-
},
23+
{ provider: 'postgresql' },
2724
);
2825

29-
const result = await db.item.createManyAndReturn({
26+
const user = await db.user.create({ data: { role: 'admin' } });
27+
28+
const result = await db.$setAuth(user).item.createManyAndReturn({
3029
data: [
3130
{ key: 'a', note: 'hello' },
3231
{ key: 'b' },

0 commit comments

Comments
 (0)