question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DATABASE_URL verification still attempted when datasource override provided in PrismaClient constructor

See original GitHub issue

Bug description

https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/constructor#datasources

When attempting to connect to the prisma client which is configured with an explicit datasource location:

const prisma = new PrismaClient({
  datasources: { postgresql: { url: "postgres://****:****@localhost:5432/****?schema=foo" } },
});
...
await prisma.$connect();

I get the following error:

(node:99546) UnhandledPromiseRejectionWarning: Error: error: Environment variable not found: DATABASE_URL.
  -->  schema.prisma:5
   | 
 4 | datasource postgresql {
 5 |   url      = env("DATABASE_URL")
   | 

Validation Error Count: 1
    at Oe.Yu.default.on.c (/Users/timleslie/src/prisma-issue/node_modules/@prisma/client/engine-core/src/NodeEngine.ts:591:29)
    at Oe.emit (events.js:197:13)
    at Oe.EventEmitter.emit (domain.js:439:20)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Oe.Readable.push (_stream_readable.js:224:10)
    at Oe.Transform.push (_stream_transform.js:151:32)
    at Oe._pushBuffer (/Users/timleslie/src/prisma-issue/node_modules/@prisma/client/engine-core/src/byline.ts:116:17)
    at Oe._transform (/Users/timleslie/src/prisma-issue/node_modules/@prisma/client/engine-core/src/byline.ts:107:8)
    at Oe.Transform._read (_stream_transform.js:190:10)
(node:99546) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:99546) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

How to reproduce

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource postgresql {
  url      = env("DATABASE_URL")
  provider = "postgresql"
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id       Int     @id @default(autoincrement())
  name     String?
}

Expected behavior

I would expect the client to never look for the DATABASE_URL environment variable if the override has been provided.

Environment & setup

  • OS: OSX 10.15.6
  • Database: PostgreSQL 12.2
  • Node.js version: 12.11.0
  • Prisma version: 2.7.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
dpetrickcommented, Nov 6, 2020

This is fixed an will be in the 2.11 release.

1reaction
pantharshit00commented, Nov 3, 2020

@DustinJSilk We are aware of this problem and we intent to tackle it in this sprint(bi weekly release schedule).

There are lot of pending issues so I wouldn’t guarantee it will 100% make it in the next release but we are aware that this is pain point.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma Client API (Reference)
datasources. Programmatically overrides properties of the datasource block in the schema.prisma file - for example, as part of an integration test ...
Read more >
How to fix Prisma Client getting undefined for custom model
To resolve that, I added a custom path for generating the prisma client inside the schema.prisma file as below - generator client {...
Read more >
Adding an API and database to your Nuxt App with Prisma
schema.prisma datasource db { provider = "sqlite" url = "file:. ... Prisma Client is an auto-generated and type-safe query builder tailored ...
Read more >
How to Get Started with Prisma ORM for Node.js and ...
Another con of using an ORM is that the query builder can't do some ... datasource db { provider = "postgresql" url =...
Read more >
@prisma/client 2.11.0 on Node.js Yarn - NewReleases.io
generator client { provider = "prisma-client-js" previewFeatures = ["nativeTypes"] } datasource db { provider = "postgresql" url = env("DATABASE_URL") } ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found