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

PSL should support inline // comments in the generator and datasource blocks #14171

Closed
jkomyno opened this issue Jul 6, 2022 · 1 comment · Fixed by prisma/prisma-engines#3050
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. tech/engines/datamodel Issue about parsing/validation/rendering of the Prisma schema topic: comments topic: prisma validate CLI: prisma validate
Milestone

Comments

@jkomyno
Copy link
Contributor

jkomyno commented Jul 6, 2022

As @tomhoule said, "comments have to be handled in a case-by-case basis in the AST, and we may not have a rule allowing trailing comments inside config blocks".

prisma validate would fail with this simple schema because of the inline comment (placed at the end of a field):

datasource db {
  provider             = "postgres"
  url                  = env("TEST_POSTGRES_URI")
  referentialIntegrity = "prisma" // = on or set to "foreignKeys" to turn off emulation
}

generator js {
  provider        = "prisma-client-js"
  previewFeatures = ["referentialIntegrity"]
} 

The error would be something like the following:

❯ npx prisma validate
Prisma schema loaded from schema.prisma
Error: Get DMMF: Schema parsing - Error while interacting with query-engine-node-api library
Error code: P1012
error: Error validating: This line is not a valid definition within a generator.
  -->  schema.prisma:9
   | 
 8 |   previewFeatures = ["referentialIntegrity"]
 9 |   referentialIntegrity = "prisma" // = on or set to "foreignKeys" to turn off emulation
10 | } 
   |

If however, we get rid of the comment (preserving the rest of the field definition as it is), everything is fine:

-  referentialIntegrity = "prisma" // = on or set to "foreignKeys" to turn off emulation
+  referentialIntegrity = "prisma"
❯ npx prisma validate
Prisma schema loaded from schema.prisma
The schema at /.../schema.prisma is valid 🚀
@jkomyno jkomyno added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: prisma validate CLI: prisma validate tech/engines/datamodel Issue about parsing/validation/rendering of the Prisma schema team/schema Issue for team Schema. labels Jul 6, 2022
@tomhoule
Copy link
Contributor

tomhoule commented Jul 6, 2022

note: this applies only to trailing comments after a key-value pair inside a config block (generator or datasource)

@Jolg42 Jolg42 changed the title PSL should support inline // comments PSL should support inline // comments in the generator and datasource blocks Jul 6, 2022
@Jolg42 Jolg42 added this to the 4.1.0 milestone Jul 8, 2022
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. team/schema Issue for team Schema. tech/engines/datamodel Issue about parsing/validation/rendering of the Prisma schema topic: comments topic: prisma validate CLI: prisma validate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants