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

[Introspection] Crashes when default value contains line breaks #1382

Closed
ejoebstl opened this issue Jan 20, 2020 · 6 comments · Fixed by prisma/prisma-engines#555
Closed
Assignees
Labels
Milestone

Comments

@ejoebstl
Copy link
Contributor

I've observed the Prisma 2 introspection code crash when a default value is not a constant, but some expression, in my case also containing a new line.

Consider a column in postgres with the following default value:

'Concatenated'||E'\n';

Introspection crashes with:

Schema parsing

error: Unexpected token. Expected one of: 
  -->  schema.prisma:389
   | 
388 |   columnName    String               @default("(Concatenated || 
389 | )")
   | ^ Unexpected token.
@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. labels Jan 21, 2020
@janpio janpio added this to the Preview 22 milestone Jan 31, 2020
@janpio janpio changed the title Introspection: Crashes when default value is not a constant Introspection: Crashes when default value contains line breaks Jan 31, 2020
@janpio
Copy link
Member

janpio commented Feb 6, 2020

Needs decision @sorenbs:

  • Can we handle this?
  • Do we want to handle this?
  • How do we want to handle this?

@janpio janpio changed the title Introspection: Crashes when default value contains line breaks [Introspection] Crashes when default value contains line breaks Feb 6, 2020
@sorenbs
Copy link
Member

sorenbs commented Feb 12, 2020

DECISION: Initially we will not support newlines in default values. If introspection encounters a default value with newlines, it should not print it.

We do not need to explicitly handle this in the parser - it is acceptable that we give random parse errors.

@janpio
Copy link
Member

janpio commented Feb 12, 2020

Slight adaptation: Let's treat this as a light guardrail, and print a comment in the schema - but not send a warning to the CLI as it doesn't make a difference right now.

@sorenbs
Copy link
Member

sorenbs commented Feb 12, 2020

Just don't spend any time trying to print a multi-line, commented-out default value. No mess like this:

model User {
  name String //@default("who thi
//nks a name should
//
//have line breaks????!?")
}

@janpio
Copy link
Member

janpio commented Feb 13, 2020

lol no - just a comment that the default value is missing here because %explanation+link%

Suggestion:

/// The default value of this field was skipped as it is currently not supported by Prisma. 
/// This does not negatively influence your app, as the default is enforced by the database.
/// Learn more at https://pris.ly/d/foo

@janpio
Copy link
Member

janpio commented Mar 17, 2020

Default value is removed - but is currently not treated as guardrail yet (which is not super important, but would be nice to have).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants