Skip to content

Commit 3612bac

Browse files
committed
fix: incorrect value type when using @default with boolean field from auth()
fixes #2038
1 parent 9c37d47 commit 3612bac

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/schema/src/plugins/prisma/schema-generator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ export class PrismaSchemaGenerator {
893893
const dummyDefaultValue = match(field.type.type)
894894
.with('String', () => new AttributeArgValue('String', ''))
895895
.with(P.union('Int', 'BigInt', 'Float', 'Decimal'), () => new AttributeArgValue('Number', '0'))
896-
.with('Boolean', () => new AttributeArgValue('Boolean', 'false'))
896+
.with('Boolean', () => new AttributeArgValue('Boolean', false))
897897
.with('DateTime', () => new AttributeArgValue('FunctionCall', new PrismaFunctionCall('now')))
898898
.with('Json', () => new AttributeArgValue('String', '{}'))
899899
.with('Bytes', () => new AttributeArgValue('String', ''))
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { loadSchema } from '@zenstackhq/testtools';
2+
3+
describe('issue 2038', () => {
4+
it('regression', async () => {
5+
const { enhance } = await loadSchema(
6+
`
7+
model User {
8+
id Int @id @default(autoincrement())
9+
flag Boolean
10+
@@allow('all', true)
11+
}
12+
13+
model Post {
14+
id Int @id @default(autoincrement())
15+
published Boolean @default(auth().flag)
16+
@@allow('all', true)
17+
}
18+
`
19+
);
20+
21+
const db = enhance({ id: 1, flag: true });
22+
await expect(db.post.create({ data: {} })).resolves.toMatchObject({
23+
published: true,
24+
});
25+
});
26+
});

0 commit comments

Comments
 (0)