Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON type is broken for array. Array comes back as string. #2619

Closed
thesunny opened this issue Jun 1, 2020 · 3 comments
Closed

JSON type is broken for array. Array comes back as string. #2619

thesunny opened this issue Jun 1, 2020 · 3 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: Json Scalar type `Json`
Milestone

Comments

@thesunny
Copy link

thesunny commented Jun 1, 2020

Bug description

When you do a prisma.table.create or prisma.table.update with an array value, the array is converted to a serialized string.

How to reproduce

Based on a minimal schema on PostgreSQL:

model stories {
  id    Int    @id @default(autoincrement())
  title String
  tags  Json
}
import { PrismaClient } from "@prisma/client"

const prisma = new PrismaClient()

async function start() {
  const data = { title: "Cool", tags: ["Matrix", "Star Wars"] }
  const createStory = await prisma.stories.create({ data })
  console.log(createStory)
  console.log(typeof createStory.tags) // returns `string`
  const story = (await prisma.stories.findMany({ take: 1 }))[0]
  console.log(story)
  console.log(typeof story.tags) // returns `string`
}

start()

Array data in a JSON field is always serialized (i.e. turned into a string). For clarity, I have checked the database and in the database, the value is also a string.

image

string, number and object work okay.

Expected behavior

When you insert an array it should be returned as an array

Prisma information

Shared above

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Prisma version: Prisma 2, beta 7
  • Node.js version: 12.16.2
@thesunny thesunny changed the title Insert and update of JSON column is broken for arrays. Arrays are serialized into a string. Insert and update of JSON column is broken for arrays. Arrays come back as a string. Jun 1, 2020
@thesunny thesunny changed the title Insert and update of JSON column is broken for arrays. Arrays come back as a string. JSON type is broken for array. Array comes back as a string. Jun 1, 2020
@thesunny thesunny changed the title JSON type is broken for array. Array comes back as a string. JSON type is broken for array. Array comes back as string. Jun 1, 2020
@thesunny
Copy link
Author

thesunny commented Jun 1, 2020

A similar issue was marked as fixed in #2432 but I am on beta 7 which is where the fix is supposed to be; however, this is a different issue.

Prisma does not throw an error, but instead saves the data as a string instead of array.

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: Json Scalar type `Json` labels Jun 1, 2020
@pantharshit00
Copy link
Contributor

pantharshit00 commented Jun 1, 2020

I can confirm the behavior and I do believe this is a bug

@janpio janpio added this to the Beta 8 milestone Jun 2, 2020
Jolg42 added a commit that referenced this issue Jun 2, 2020
Related: JSON type is broken for array. Array comes back as `string`. #2619
@Jolg42
Copy link
Member

Jolg42 commented Jun 2, 2020

This is now fixed in 2.0.0-alpha.1286

Thanks for the 👌 issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: Json Scalar type `Json`
Projects
None yet
Development

No branches or pull requests

4 participants