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.

Escaped password working with psql but not Prisma Client

See original GitHub issue

Bug description

Hello I have a generated password that is )u&rI5]FlgG|1)q57rpB8-4{S3~5?7G}. Obviously it needs to be properly escaped, so I’ve made to the point where I’ve escaped the password enough to be working with psql

psql postgres://user:\)u\&rI5]FlgG\|1\)q57rpB8-4{S3~5\?7G}@localhost:5432
  • \)u\&rI5]FlgG\|1\)q57rpB8-4{S3~5\?7G} ✅ with psql
  • \)u\&rI5]FlgG\|1\)q57rpB8-4{S3~5\?7G} ❌ with prisma
  • )u&rI5]FlgG|1)q57rpB8-4{S3~5?7G} ❌ with psql and prisma

I’ve tried several escaping combinations, as well as URLEncoding the password, but I’ve never got to the point where what was working with psql was also working with prisma client.

Thanks in advance for any help! 🙏

How to reproduce

Prisma version "@prisma/client": "2.16.1",

Setup a PostgreSQL docker container

  postgresql:
    image: postgres:latest
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: )u&rI5]FlgG|1)q57rpB8-4{S3~5?7G}

schema.prisma

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

datasource db {
  provider = "postgres"
  url      = env("POSTGRES_URL")
}

.env

POSTGRES_URL="postgres://user:\)u\&rI5]FlgG\|1\)q57rpB8-4{S3~5\?7G}@localhost:5432"

Run prisma migrate reset --preview-feature

The command above fails with the following error:

$ prisma migrate reset --preview-feature
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database ")u\&rI5]FlgG\|1\)q57rpB8-4{S3~5\", schema "public" at "user::undefined"

Error: undefined: error: Error validating: This line is not a valid definition within a datasource.
  -->  schema.prisma:4
   |
 3 |                 provider = "postgresql"
 4 |                 url = "postgres://user:\)u\&rI5]FlgG\|1\)q57rpB8-4{S3~5\?7G}@localhost:5432"
 5 |             }
   |

Expected behavior

I’d expect the escaped password working with psql to work with prisma client

Prisma information

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

datasource db {
  provider = "postgres"
  url      = env("POSTGRES_URL")
}

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v15.12.0
  • Prisma version:
prisma               : 2.16.1
@prisma/client       : 2.16.1
Current platform     : darwin
Query Engine         : query-engine 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio               : 0.346.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
emyanncommented, Apr 6, 2021

@janpio Same error unfortunately with the string you shared

$ prisma migrate reset --preview-feature
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database ")u\&rI5]FlgG\|1\)q57rpB8-4{S3~5\", schema "public" at "user::undefined"

Error: undefined: error: Error validating: This line is not a valid definition within a datasource.
  -->  schema.prisma:4
   |
 3 |                 provider = "postgresql"
 4 |                 url = "postgres://user:\)u\&rI5]FlgG\|1\)q57rpB8-4{S3~5\?7G}@localhost:5432"
 5 |             }
   |

0reactions
pantharshit00commented, Feb 25, 2022

@1323ED5 We can’t encode it ourselves because then we won’t be able to determine termination points of various parts of the URL that are determined by special characters like @

Read more comments on GitHub >

github_iconTop Results From Across the Web

prisma can't connect to postgresql - Stack Overflow
I've tried to connect Prisma with postgreSQL several times. prisma show this error message : "Error: undefined: invalid port number in " ...
Read more >
Database connection not allowing back slash or maybe other ...
The connection should be successful even if the password has special characters, since they were escaped in the DATABASE_URL. Prisma information.
Read more >
Connection URLs (Reference) - Prisma
Prisma needs a connection URL to be able to connect to your database, e.g. when sending queries with Prisma Client or when changing...
Read more >
Raw database access (Reference) - Prisma
Learn how you can send raw SQL and MongoDB queries to your database using the raw() methods from the Prisma Client API.
Read more >
PostgreSQL database connector (Reference) - Prisma
Connection URL. Prisma is based on the official PostgreSQL format for connection URLs, but does not support all arguments and includes additional arguments...
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