Prisma: Introspect default value with backslashes causes problem when generating client

Created on 20 Mar 2020  Â·  3Comments  Â·  Source: prisma/prisma

Bug description

Backslashes in SQL default values are not escaped properly and consequently return an invalid schema when introspecting.

How to reproduce

  1. Create table with one or more columns containing backslashes in the default value
CREATE TABLE test (
    `model_name_space` VARCHAR(255) NOT NULL DEFAULT 'xyz\\Datasource\\Model'
)
  1. Introspect the database schema (prisma2 introspect)
  2. Generate client (prisma2 generate fails)

The generated schema will look like this:

model test {
    model_name_space    String    @default("xyz\Datasource\Model")
}

The following error is thrown when generating the client:

➜  prisma npx prisma2 generate  
Error: Schema parsing
error: Unexpected token. Expected one of: string interpolation start
  -->  schema.prisma:1552
     | 
1552 |   model_name_space                 String                          @default("xyz\Datasource\Model")
     |                                                                                 ^ Unexpected token.
     |

Expected behavior

Backslashes in the default value should be escaped.

model test {
    model_name_space    String    @default("xyz\\Datasource\\Model")
}

Prisma information

Environment & setup

bu2-confirmed kinbug tecengines introspection

Most helpful comment

We are aware of this and will work on it soon: https://github.com/prisma/prisma-engines/issues/691

All 3 comments

We are aware of this and will work on it soon: https://github.com/prisma/prisma-engines/issues/691

I just merged https://github.com/prisma/prisma-engines/pull/738, which should address this issue. The fix should be in alpha 1213 and will for sure be in beta 6. If you have the time, can you confirm that it solves your problem?

Hi @tomhoule, I am still able to reproduce the issue on @prisma/cli 2.0.0-alpha.1213. Backslashes aren't escaped properly. But the error changed and the issue now is harder to identify, as every row of the model containing backslashes in the default value now has an error like this:
Error validating: This line is invalid. It does not start with any known Prisma schema keyword.

Was this page helpful?
0 / 5 - 0 ratings