Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Error when passing a null value to a nullable Json field type #693

Closed
radicand opened this issue May 8, 2020 · 2 comments
Closed

Error when passing a null value to a nullable Json field type #693

radicand opened this issue May 8, 2020 · 2 comments
Assignees
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: json
Milestone

Comments

@radicand
Copy link

radicand commented May 8, 2020

Bug description

When attempting to insert a null value for a nullable Json field, an error is thrown in Prisma Client

I haven't dived into this in great depth, but on https://github.com/prisma/prisma/blob/master/src/packages/client/src/runtime/query.ts#L684 , obj.values is accessed before obj is checked for null; perhaps the root cause.

How to reproduce

  1. Create a model with a nullable Json field (e.g., Json?)
  2. Insert a null
  3. Crash
// For the below object to be created against the schema below:
debug: generation options: {"metric":"metric_two","details":null}
error: TypeError: Cannot read property 'values' of null
    at stringify (.../node_modules/@prisma/client/src/runtime/query.ts:684:13)
    at Arg._toString (.../node_modules/@prisma/client/src/runtime/query.ts:772:23)
    at Arg.toString (.../node_modules/@prisma/client/src/runtime/query.ts:781:17)
...

Expected behavior

Null to be inserted

Prisma information

Sanitized schema:

model metrics {
  details                   Json?
  id                        Int                        @default(autoincrement()) @id
  metric                    metrics_metric?
  createdAt                 DateTime                   @default(now())
  updatedAt                 DateTime                   @updatedAt

  @@index([metric], name: "metrics_metric")
}
enum metrics_metric {
  metric_one
  metric_two @map("metric-two")
  three
}

Environment & setup

  • OS: Mac OS
  • Database: MySQL 5.7
  • Prisma version: 2.0.0-alpha.1198
  • Node.js version: v13.13.0
@pantharshit00 pantharshit00 transferred this issue from prisma/prisma May 16, 2020
@pantharshit00 pantharshit00 added bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. process/candidate Candidate for next Milestone. topic: json labels May 16, 2020
@pantharshit00
Copy link
Contributor

pantharshit00 commented May 16, 2020

Thanks, I can confirm the issue. The query doesn't even reach the engine it is an error in our client code as you already pointed out.

The query I used along with the model that you provided in order to reproduce this issue:

  const data = await client.metrics.create({
    data: {
      metric: null,
      details: null,
    },
  });

image

Version information:

Environment variables loaded from ./prisma/.env
@prisma/cli          : 2.0.0-alpha.1217
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 0b7f6a9f901fa5635e23a8d5f1dbe0ec273a3a11 (at /home/harshit/code/reproductions/issue-2399/node_modules/@prisma/cli/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 0b7f6a9f901fa5635e23a8d5f1dbe0ec273a3a11 (at /home/harshit/code/reproductions/issue-2399/node_modules/@prisma/cli/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 0b7f6a9f901fa5635e23a8d5f1dbe0ec273a3a11 (at /home/harshit/code/reproductions/issue-2399/node_modules/@prisma/cli/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 0b7f6a9f901fa5635e23a8d5f1dbe0ec273a3a11 (at /home/harshit/code/reproductions/issue-2399/node_modules/@prisma/cli/prisma-fmt-debian-openssl-1.1.x)

@janpio janpio added the tech/typescript Issue for tech TypeScript. label May 19, 2020
@janpio janpio removed the process/candidate Candidate for next Milestone. label May 26, 2020
@janpio janpio added this to the Beta 7 milestone May 26, 2020
Jolg42 added a commit to prisma/prisma that referenced this issue May 28, 2020
@Jolg42
Copy link
Member

Jolg42 commented May 28, 2020

Thank you for the issue!

This is now fixed in the latest alpha (2.0.0-alpha.1263).

@Jolg42 Jolg42 closed this as completed May 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: json
Projects
None yet
Development

No branches or pull requests

4 participants