From edaabe848498f5cec46b1cf627ef744d1d00ae8b Mon Sep 17 00:00:00 2001 From: Mike Willbanks Date: Wed, 19 Nov 2025 01:56:44 +0000 Subject: [PATCH] fix(#423): avoid coercing non-validators to bigint * stop coercing mapped attribute values into BigInt inside addBigIntValidation, limiting conversion to real validator attributes * add regression test proving @map-decorated BigInt fields create and update successfully --- packages/orm/src/client/crud/validator/utils.ts | 10 +++++----- tests/regression/test/issue-423.test.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 tests/regression/test/issue-423.test.ts diff --git a/packages/orm/src/client/crud/validator/utils.ts b/packages/orm/src/client/crud/validator/utils.ts index 94f4baca..657ab804 100644 --- a/packages/orm/src/client/crud/validator/utils.ts +++ b/packages/orm/src/client/crud/validator/utils.ts @@ -125,19 +125,19 @@ export function addBigIntValidation(schema: z.ZodBigInt, attributes: AttributeAp if (val === undefined) { continue; } - const bigIntVal = BigInt(val); + match(attr.name) .with('@gt', () => { - result = result.gt(bigIntVal); + result = result.gt(BigInt(val)); }) .with('@gte', () => { - result = result.gte(bigIntVal); + result = result.gte(BigInt(val)); }) .with('@lt', () => { - result = result.lt(bigIntVal); + result = result.lt(BigInt(val)); }) .with('@lte', () => { - result = result.lte(bigIntVal); + result = result.lte(BigInt(val)); }); } return result; diff --git a/tests/regression/test/issue-423.test.ts b/tests/regression/test/issue-423.test.ts new file mode 100644 index 00000000..4b0ee49f --- /dev/null +++ b/tests/regression/test/issue-423.test.ts @@ -0,0 +1,16 @@ +import { createTestClient } from '@zenstackhq/testtools'; +import { describe, expect, it } from 'vitest'; + +describe('Regression for issue #423', () => { + it('verifies non-validation attributes for BigInt does not fail', async () => { + const db = await createTestClient( + ` +model SampleBigInt { + id BigInt @id @map("sample_id") + data String +}`, + ); + await expect(db.SampleBigInt.create({ data: { data: "create", id: BigInt(1) } })).resolves.toMatchObject({ id: BigInt(1), data: "create" }); + await expect(db.SampleBigInt.update({ data: { data: "update" }, where: { id: BigInt(1) } })).resolves.toMatchObject({ id: BigInt(1), data: "update" }); + }); +});