Prisma 6.6.0: Unable To Use Prisma.JsonNull And Prisma.DbNull Due To "We Could Not Serialize [object Function] Value."

by ADMIN 119 views

Prisma 6.6.0: Unable to use Prisma.JsonNull and Prisma.DbNull due to "We could not serialize [object Function] value."

Bug Description

After updating to Prisma 6.6.0, several users have been facing an issue where they are unable to use Prisma.JsonNull and Prisma.DbNull due to a serialization error. This error occurs when trying to insert a JSON null or DB null value into the database.

Severity

⚠️ Major: Breaks core functionality (e.g., migrations fail)

Reproduction

  1. Create a schema with an optional JSON field.
  2. Try creating an entry of the defined schema.
  3. Use Prisma.JsonNull or Prisma.DbNull for the JSON field.

Expected vs. Actual Behavior

Expected: JSON null/DB null value is being inserted into the database.

Actual: An error is thrown due to serialization issues.

Frequency

Consistently reproducible.

Does this occur in development or production?

Both development and production.

Is this a regression?

Yes, it broke in Prisma 6.6.0.

Workaround

For now, trying to pass "undefined" and not null value.

Prisma Schema & Queries

model Authorization {
  //...
  metadata Json? @map("metadata")
  walletMetadata Json? @map("wallet_metadata")
const created = await this.prisma.authorization.create({
    data: {
        ...rest,
        accountId: accountIdSchemaRemoveDashes.parse(accountId),
        presentationDefinition: presentationDefinition ?? Prisma.JsonNull,
        status: 'created',
        walletMetadata: walletMetadata ?? Prisma.JsonNull,
        metadata: metadata ?? Prisma.JsonNull,
    },
});

Prisma Config

// Add your `prisma.config.ts`

Logs & Debug Info

[POST] /openid4/vp/v1_0/authorizations >> Status: <no-status>, Message: Something went wrong, Internal message: <no-internal-message> PrismaClientValidationError: 
Invalid `this.prisma.authorization.create()` invocation in
/Users/antonioivanovski/dev/vidos/packages/authorizer/src/services/authorization.ts:35:57
  32 
  33 console.log(Prisma.DbNull, Prisma.JsonNull);
  34 
→ 35 const created = await this.prisma.authorization.create({
       data: {
         authorizationId: "a-7973d515-f813-467d-b6ab-0ae1b36d7349",
         expiresAt: new Date("2025-04-25T19:00:34.505Z"),
         instanceResourceId: "local-test",
         nonce: "n-68d1a9ea-0281-4a6b-9e63-080cfc2e1579",
         responseMode: "direct_post",
         responseType: "vp_token",
         scope: "openid",
         state: "s-cde97147-6ee8-44e4-810a-bc12636cb0f1",
         accountId: "rf2b62a7tt1ec5",
         presentationDefinition: {
           id: "VerifiablePortableDocumentA1",
           input_descriptors:             {
               id: "constraint-1",
               format: {
                 vc+sd-jwt: {
                   alg: [
                     "ES256"
                   ]
                 },
                 vp+sd-jwt: {
                   alg: [
                     "ES256"
                   ]
                 }
               },
               constraints: {
                 limit_disclosure: "required",
                 fields: [
                   {
                     path: [
                       "$.vct"
                     ],
                     filter: {
                       contains: {
                         const: "VerifiablePortableDocumentA1"
                       },
                       type: "string"
                     }
                   },
                   {
                     path: [
                       "$.section1"
                     ]
                   },
                   {
                     path: [
                       "$.section2"
                     ]
                   },
                   {
                     path: [
                       "$.section3"
                     ]
                   },
                   {
                     path: [
                       "$.section4"
                     ]
                   },
                   {
                     path: [
                       "$.section5"
                     ]
                   },
                   {
                     path: [
                       "$.section6"
                     ]
                   }
                 ]
               }
             }
           ]
         },
         status: "created",
         walletMetadata: [object Function],
                         ~~~~~~~~~~~~~~~~~
         metadata: [object Function]
       }
     })
Invalid value for argument `walletMetadata`: We could not serialize [object Function] value. Serialize the object to JSON or implement a ".toJSON()" method on it.
    at Pn (file:///Users/antonioivanovski/dev/vidos/node_modules/.pnpm/@prisma+client@6.6.0_prisma@6.6.0_typescript@5.7.2__typescript@5.7.2/node_modules/@prisma/client/runtime/library.mjs:36:1363)
    at e.throwValidationError (file:///Users/antonioivanovski/dev/vidos/node_modules/.pnpm/@prisma+client@6.6.0_prisma@6.6.0_typescript@5.7.2__typescript@5.7.2/node_modules/@prisma/client/runtime/library.mjs:36:10051)
    at wa (file:///Users/antonioivanovski/dev/vidos/node_modules/.pnpm/@prisma+client@6.6.0_prisma@6.6.0_typescript@5.7.2__typescript@5.7.2/node_modules/@prisma/client/runtime/library.mjs:36:8282)
    at xa (file:///Users/antonioivanovski/dev/vidos/node_modules/.pnpm/@prisma+client@6.6.0_prisma@6.6.0_typescript@5.7.2__typescript@5.7.2/node_modules/@prisma/client/runtime/library.mjs:36:8741)
    at wa (file:///Users/antonioivanovski/dev/vidos/node_modules/.pnpm/@prisma+client@6.6.0_prisma@6.6.0_typescript@5.7.2__typescript@5.7.2/node_modules/@prisma/client/runtime/library.mjs:36:8272)
    at xa (file:///Users/antonioivanovski/dev/vidos/node_modules/.pnpm/@prisma+client@6.6.0_prisma@6.6.0_typescript@5.7.2__typescript@5.7.2/node_modules/@prisma/client/runtime/library.mjs:36:8741)
    at gt (file:///Users/antonioivanovski/dev/vidos/node_modules/.pnpm/@prisma+client@6.6.0_prisma@6.6.0_typescript@5.7.2__typescript@5.7.2/node_modules/@prisma/client/runtime/library.mjs:36:5845)
    at Gi (file:///Users/antonioivanovski/dev/vidos/node_modules/.pnpm/@prisma+client@6.6.0_prisma@6.6.0_typescript@5.7.2__typescript@5.7.2/node_modules/@prisma/client/runtime/library.mjs:36:5747)
    at file:///Users/antonioivanovski/dev/vidos/node_modules/.pnpm/@prisma+client@6.6.0_prisma@6.6.0_typescript@5.7.2__typescript@5.7.2/node_modules/@prisma/client/runtime/library.mjs:137:10272
    at Object.runInChildSpan (file:///Users/antonioivanovski/dev/vidos/node_modules/.pnpm/@prisma+client@6.6.0_prisma@6.6.0_typescript@5.7.2__typescript@5.7.2/node_modules/@prisma/client/runtime/library.mjs:128:1549) {
  clientVersion: '6.6.0'
}

Environment & Setup

  • OS: Both MacOs and Linux
  • Database: PostgreSQL
  • Node.js version: v20.18.3

Prisma Version

prisma                  : 6.6.0
@prisma/client          : 6.6.0
Computed binaryTarget   : darwin
Operating System        : darwin
Architecture            : x64
Node.js                 : v20.18.3
TypeScript              : 5.7.2
Query Engine (Node-API) : libquery-engine f676762280b54cd07c770017ed3711ddde35f37a (at node_modules/.pnpm/@prisma+engines@6.6.0/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Schema Engine           : schema-engine-cli f676762280b54cd07c770017ed3711ddde35f37a (at node_modules/.pnpm/@prisma+engines@6.6.0/node_modules/@prisma/engines/schema-engine-darwin)
Schema Wasm             : @prisma/prisma-schema-wasm 6.6.0-53.f676762280b54cd07c770017ed3711ddde35f37a
Default Engines Hash    : f676762280b54cd07c770017ed3711<br/>
**Prisma 6.6.0: Unable to use Prisma.JsonNull and Prisma.DbNull due to "We could not serialize [object Function] value." - Q&A**

**Q: What is the issue with Prisma 6.6.0?**

A: The issue is that Prisma 6.6.0 is unable to use `Prisma.JsonNull` and `Prisma.DbNull` due to a serialization error. This error occurs when trying to insert a JSON null or DB null value into the database.

**Q: What are the symptoms of this issue?**

A: The symptoms of this issue include:

* Unable to create entries with JSON null or DB null values
* Serialization error when trying to insert JSON null or DB null values
* Error message: "We could not serialize [object Function] value."

**Q: What are the possible causes of this issue?**

A: The possible causes of this issue include:

* Prisma 6.6.0 bug
* Incompatible database schema
* Incorrect Prisma configuration

**Q: How can I reproduce this issue?**

A: To reproduce this issue, follow these steps:

1. Create a schema with an optional JSON field.
2. Try creating an entry of the defined schema.
3. Use `Prisma.JsonNull` or `Prisma.DbNull` for the JSON field.

**Q: What are the expected and actual behaviors?**

A: The expected behavior is that JSON null/DB null value is being inserted into the database.

The actual behavior is that an error is thrown due to serialization issues.

**Q: What is the workaround for this issue?**

A: For now, trying to pass "undefined" and not `null` value.

**Q: What are the system requirements for this issue?**

A: The system requirements for this issue include:

* Prisma 6.6.0
* PostgreSQL database
* Node.js version v20.18.3

**Q: How can I troubleshoot this issue?**

A: To troubleshoot this issue, follow these steps:

1. Check the Prisma version and ensure it is up-to-date.
2. Verify the database schema and ensure it is compatible with Prisma 6.6.0.
3. Check the Prisma configuration and ensure it is correct.
4. Review the error message and logs to identify the root cause of the issue.

**Q: What are the next steps to resolve this issue?**

A: The next steps to resolve this issue include:

1. Reporting the issue to Prisma support
2. Providing detailed logs and error messages
3. Collaborating with Prisma support to resolve the issue

**Q: Is this issue a regression?**

A: Yes, it broke in Prisma 6.6.0.

**Q: Does this issue occur in development or production?**

A: Both development and production.

**Q: What are the possible solutions to this issue?**

A: The possible solutions to this issue include:

1. Updating to a newer Prisma version
2. Modifying the database schema to be compatible with Prisma 6.6.0
3. Correcting the Prisma configuration

**Q: How can I prevent this issue in the future?**

A: To prevent this issue in the future, follow these best practices:

1. Regularly update Prisma to the latest version.
2. the database schema and ensure it is compatible with Prisma.
3. Review the Prisma configuration and ensure it is correct.

By following these best practices and troubleshooting steps, you can prevent this issue and ensure a smooth Prisma experience.