@@ -116,7 +116,7 @@ describe('Custom validation tests', () => {
116116 }
117117 } ) ;
118118
119- it ( 'allows disabling validation' , async ( ) => {
119+ it ( 'disabling validation makes validation attributes ineffective ' , async ( ) => {
120120 const db = await createTestClient (
121121 `
122122 model User {
@@ -180,6 +180,95 @@ describe('Custom validation tests', () => {
180180 ) . toBeRejectedByValidation ( ) ;
181181 } ) ;
182182
183+ it ( 'disabling validation skips structural validation for all CRUD operations' , async ( ) => {
184+ const db = await createTestClient (
185+ `
186+ model User {
187+ id Int @id @default(autoincrement())
188+ email String
189+ name String
190+ }
191+ ` ,
192+ ) ;
193+
194+ const dbNoValidation = db . $setOptions ( { ...db . $options , validateInput : false } ) ;
195+
196+ // Helper: assert that a promise rejects but NOT with a Zod-based validation error
197+ // (the cause of a Zod validation error is a ZodError)
198+ const expectNonValidationError = async ( promise : Promise < unknown > ) => {
199+ try {
200+ await promise ;
201+ } catch ( err : any ) {
202+ if ( err . reason === 'invalid-input' ) {
203+ expect ( err . cause ?. constructor ?. name ) . not . toBe ( 'ZodError' ) ;
204+ }
205+ return ;
206+ }
207+ // resolving is also acceptable — it means validation was skipped and the ORM handled it
208+ } ;
209+
210+ // create - missing required "data" is normally rejected by Zod validation
211+ await expect ( db . user . create ( { } as any ) ) . toBeRejectedByValidation ( ) ;
212+ // with validation disabled, it skips Zod validation
213+ await expectNonValidationError ( dbNoValidation . user . create ( { } as any ) ) ;
214+
215+ // update - missing required "where" is normally rejected by Zod validation
216+ await expect ( db . user . update ( { data : { email : 'new@b.com' } } as any ) ) . toBeRejectedByValidation ( ) ;
217+ await expectNonValidationError ( dbNoValidation . user . update ( { data : { email : 'new@b.com' } } as any ) ) ;
218+
219+ // delete - missing required "where" is normally rejected by Zod validation
220+ await expect ( db . user . delete ( { } as any ) ) . toBeRejectedByValidation ( ) ;
221+ await expectNonValidationError ( dbNoValidation . user . delete ( { } as any ) ) ;
222+
223+ // upsert - missing required fields is normally rejected by Zod validation
224+ await expect ( db . user . upsert ( { } as any ) ) . toBeRejectedByValidation ( ) ;
225+ await expectNonValidationError ( dbNoValidation . user . upsert ( { } as any ) ) ;
226+ } ) ;
227+
228+ it ( '$setInputValidation toggles validation' , async ( ) => {
229+ const db = await createTestClient (
230+ `
231+ model Item {
232+ id Int @id @default(autoincrement())
233+ url String @url
234+ }
235+ ` ,
236+ ) ;
237+
238+ // validation enabled by default
239+ await expect ( db . item . create ( { data : { url : 'not-a-url' } } ) ) . toBeRejectedByValidation ( ) ;
240+
241+ // disable via $setInputValidation
242+ const dbDisabled = db . $setInputValidation ( false ) ;
243+ await expect ( dbDisabled . item . create ( { data : { url : 'not-a-url' } } ) ) . toResolveTruthy ( ) ;
244+
245+ // re-enable via $setInputValidation
246+ const dbReEnabled = dbDisabled . $setInputValidation ( true ) ;
247+ await expect ( dbReEnabled . item . create ( { data : { url : 'still-not-a-url' } } ) ) . toBeRejectedByValidation ( ) ;
248+
249+ // valid data should work with re-enabled validation
250+ await expect ( dbReEnabled . item . create ( { data : { url : 'https://example.com' } } ) ) . toResolveTruthy ( ) ;
251+ } ) ;
252+
253+ it ( 'disabling validation at client creation time' , async ( ) => {
254+ const db = await createTestClient (
255+ `
256+ model Post {
257+ id Int @id @default(autoincrement())
258+ title String @length(min: 5)
259+ }
260+ ` ,
261+ { validateInput : false } ,
262+ ) ;
263+
264+ // should skip validation since validateInput is false from the start
265+ await expect ( db . post . create ( { data : { id : 1 , title : 'ab' } } ) ) . toResolveTruthy ( ) ;
266+
267+ // re-enable validation
268+ const dbValidated = db . $setInputValidation ( true ) ;
269+ await expect ( dbValidated . post . create ( { data : { title : 'ab' } } ) ) . toBeRejectedByValidation ( ) ;
270+ } ) ;
271+
183272 it ( 'checks arg type for validation functions' , async ( ) => {
184273 // length() on relation field
185274 await loadSchemaWithError (
0 commit comments