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

Unable to specify a double quote in a string default value #8902

Closed
xytxytxyt opened this issue Aug 24, 2021 · 7 comments
Closed

Unable to specify a double quote in a string default value #8902

xytxytxyt opened this issue Aug 24, 2021 · 7 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. tech/engines/datamodel Issue about parsing/validation/rendering of the Prisma schema topic: default
Milestone

Comments

@xytxytxyt
Copy link

xytxytxyt commented Aug 24, 2021

Bug description

I am unable to specify a " character in a string default value in the Prisma schema.

How to reproduce

model MyTable {
  id                         Int                    @id @default(autoincrement())
  myColumn                   String                 @default("unable to specify a double quote in this string")
}

@default('"') is invalid
@default("\"") is invalid
@default("""") is invalid

Expected behavior

There should be a way to specify a double quote in a string default value.

Prisma information

model MyTable {
  id                         Int                    @id @default(autoincrement())
  myColumn                   String                 @default("unable to specify a double quote in this string")
}

No client queries yet because I am unable to write a valid Prisma schema.

This is actually a simplified reproduction of my use case which is a Postgres Jsonb column:
myColumn Json @default("{'1': {}, '2': {}, '3': {}, '4': {}}")
This is valid Prisma, but will result in invalid JSON. It should be {"1": {}, "2": {}, "3": {}, "4": {}} but I am unable to specify this in the schema.

My current workaround is letting the migrate fail, then hand-editing migration.sql to have the correct default value.

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v15.6.0

Prisma Version

prisma               : 2.29.1
@prisma/client       : 2.29.1
Current platform     : darwin
Query Engine         : query-engine 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 1be4cd60b89afa04b192acb1ef47758a39810f3a
Studio               : 0.419.0
@xytxytxyt xytxytxyt added the kind/bug A reported bug. label Aug 24, 2021
@tomhoule tomhoule added this to the 2.31.0 / 3.0.x milestone Aug 25, 2021
@tomhoule tomhoule added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. tech/engines/datamodel Issue about parsing/validation/rendering of the Prisma schema team/schema Issue for team Schema. and removed process/candidate labels Aug 25, 2021
@janpio janpio modified the milestones: 2.31.0 / 3.0.x, 3.1.0 Sep 9, 2021
@tomhoule tomhoule removed their assignment Sep 22, 2021
@tomhoule tomhoule modified the milestones: 3.1.0, 3.2.0 Sep 22, 2021
@tomhoule
Copy link
Contributor

Another instance of #4167

@tomhoule
Copy link
Contributor

I wrote a test to try to reproduce this problem in prisma/prisma-engines#2260 — additionally, I checked that we do already have a test for migrate that this works, so I'm a bit at a loss about fixing this. Can you still reproduce the issue with a recent (3+) version of Prisma?

@tomhoule tomhoule removed their assignment Sep 27, 2021
@xytxytxyt
Copy link
Author

i see, the solution is to upgrade to 3.x?

@tomhoule
Copy link
Contributor

I'm not sure this is the fix, since I haven't tried reproducing the issue on 2.29. I'll spend some time doing that.

@tomhoule tomhoule self-assigned this Sep 28, 2021
@tomhoule
Copy link
Contributor

Ok I did try with 2.29.1, and \" seems to work. My schema:

datasource db {
    provider = "sqlite"
    url = "file:dev.db"
}

model MyTable {
  id                         Int                    @id @default(autoincrement())
  myColumn                   String                 @default("unable to specify a \"double quote in this string")
}

It passes validation. I also created and applied a (sqlite) migration:

-- CreateTable
CREATE TABLE "MyTable" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "myColumn" TEXT NOT NULL DEFAULT 'unable to specify a "double quote in this string'
);

which applies cleanly.

I then did the same on postgres:

-- CreateTable
CREATE TABLE "MyTable" (
    "id" SERIAL NOT NULL,
    "myColumn" TEXT NOT NULL DEFAULT E'unable to specify a "double quote in this string',

    PRIMARY KEY ("id")
);

Which also seems to apply cleanly.

prisma               : 2.29.1
@prisma/client       : Not found
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 1be4cd60b89afa04b192acb1ef47758a39810f3a (at ../../.cache/node_modules/lib/node_modules/prisma/node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 1be4cd60b89afa04b192acb1ef47758a39810f3a (at ../../.cache/node_modules/lib/node_modules/prisma/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 1be4cd60b89afa04b192acb1ef47758a39810f3a (at ../../.cache/node_modules/lib/node_modules/prisma/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 1be4cd60b89afa04b192acb1ef47758a39810f3a (at ../../.cache/node_modules/lib/node_modules/prisma/node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : 1be4cd60b89afa04b192acb1ef47758a39810f3a
Studio               : 0.419.0

Can you still reproduce the problem on 2.29.1?

@tomhoule tomhoule removed their assignment Sep 29, 2021
@xytxytxyt
Copy link
Author

xytxytxyt commented Sep 29, 2021

i just checked, and it \" does indeed seem to work

i'm mystified now as to why it wasn't working in the first place... closest i can figure is maybe it was working the whole time but vscode mistakenly showed it as invalid

apologies for the wild goose chase, thanks for your help!

@tomhoule
Copy link
Contributor

No problem, glad it's working now :) One possible explanation is that you maybe had an old version of the vscode extension. We definitely had problems with string literal escaping in the Prisma Schema Language in the past because they're ill defined (it's a bit of a pet peeve of mine), so it's likely that it didn't work until a few months ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. tech/engines/datamodel Issue about parsing/validation/rendering of the Prisma schema topic: default
Projects
None yet
Development

No branches or pull requests

3 participants