Prisma-client-js: It is possible to have empty values in database source url

Created on 3 Dec 2019  路  10Comments  路  Source: prisma/prisma-client-js

Right now we are able to have empty values in the datasource url(either by hard coding or by environment variable) which cause a runtime error when we try to execute the client.

Schema:

generator photon {
  provider = "photonjs"
}

datasource db {
  provider = "postgresql"
  url      = ""
}

model User {
  id    String  @default(cuid()) @id
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        String   @default(cuid()) @id
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  published Boolean  @default(true)
  title     String
  content   String?
  author    User?
}

Error:
image

Refer: https://github.com/prisma/photonjs/issues/305#issuecomment-559559485

bu2-confirmed kinbug tecengines

Most helpful comment

This probably should be disallowed, it should return a clear error that you have to specify a datasource URL. Related: prisma-labs/nexus-prisma#546 (comment)

Either that should be the case or we could use the defaults for example postgresql://localhost:5432/postgres?schema=public is used by many clients as the default value.

In my opinion this should be a hard error. Then you can't forget to set the connection string when switching environments.

All 10 comments

What would correct or expected behaviour be in this case @pantharshit00?

This probably should be disallowed, it should return a clear error that you have to specify a datasource URL. Related: https://github.com/prisma-labs/nexus-prisma/issues/546#issuecomment-561808751

Thank you @steebchen

@janpio and @pantharshit00 please also have a look at this comment https://github.com/prisma-labs/nexus-prisma/issues/546#issuecomment-561834082

This probably should be disallowed, it should return a clear error that you have to specify a datasource URL. Related: prisma-labs/nexus-prisma#546 (comment)

Either that should be the case or we could use the defaults for example postgresql://localhost:5432/postgres?schema=public is used by many clients as the default value.

This probably should be disallowed, it should return a clear error that you have to specify a datasource URL. Related: prisma-labs/nexus-prisma#546 (comment)

Either that should be the case or we could use the defaults for example postgresql://localhost:5432/postgres?schema=public is used by many clients as the default value.

In my opinion this should be a hard error. Then you can't forget to set the connection string when switching environments.

@sorenbs You're assigned to make a product decision here. For me, it's clear that an empty value should be disallowed, especially because it will result in unclear errors. If we ever have default connection string values, we can re-open for discussion, but for now I think this should be disallowed.

The related issue in specs: https://github.com/prisma/specs/issues/365

There's also an issue how this behaves with empty environment values, but that's a different discussion.

A decision has been made by @sorenbs: Just disallow it

Next steps:

  • @divyenduz figures out if this has to be reflected in Error spec etc
  • @timsuchanek and @mavilein figure out who has to work on this

This has two aspects wrt the errors spec:

Static empty value: this should be disallowed by the schema parser and would be covered via https://github.com/prisma/prisma-engines/blob/master/libs/user-facing-errors/src/common.rs#L180-L184

Depending on what the default error from schema parser is, we might want to handle this separately but I think SchemaParserError (P1012) should suffice.

Dynamic empty value: this can be set via an environment variable, in this case schema parser and prisma2 generate command cannot know that the value is empty and the earliest point where the value is resolved is Prisma client's constructor. At that point it can fail with an error citing fulfillment of the specific env var (related issue https://github.com/prisma/specs/issues/369).

image

image

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

divyenduz picture divyenduz  路  3Comments

maartenraes picture maartenraes  路  4Comments

timsuchanek picture timsuchanek  路  4Comments

williamluke4 picture williamluke4  路  3Comments

FluorescentHallucinogen picture FluorescentHallucinogen  路  3Comments