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

[Driver Adapters]: missing provider compatibility validation #21864

Closed
jkomyno opened this issue Nov 9, 2023 · 1 comment · Fixed by #24481
Closed

[Driver Adapters]: missing provider compatibility validation #21864

jkomyno opened this issue Nov 9, 2023 · 1 comment · Fixed by #24481
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. topic: driverAdapters topic: preview 👁
Milestone

Comments

@jkomyno
Copy link
Contributor

jkomyno commented Nov 9, 2023

Consider this (internal) Notion doc.

Considering this schema.prisma:

generator client {
  provider = "prisma-client-js"
  engineType = "library"
  previewFeatures = ["driverAdapters"]
}

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

The schema clearly uses the postgres provider.

Now consider a TypeScript snippet in which we load planetscale's Driver Adapter:

import { connect } from '@planetscale/database'
import { PrismaPlanetScale } from '@prisma/adapter-planetscale'
import { PrismaClient } from '@prisma/client'

const connectionString = `${process.env.DATABASE_URL}`

const connection = connect({ url: connectionString })
const adapter = new PrismaPlanetScale(connection)
const prisma = new PrismaClient({ adapter })

// use Prisma as usual on any model, e.g., `user`
await prisma.user.findMany()

The schema clearly uses the postgres provider, yet we are allowed to load the planetscale's Driver Adapter, which should required the mysql provider. One can construct a particularly dangerous example in which, as long as the remote mysql-based database has the same table definitions as the ones inferred in TypeScript from the Prisma schema, the user could accidentally write to the wrong database, and Prisma Client would give absolutely no indication of this mishap.

So, we're missing a runtime validation error, which could be phrased as:

The Driver Adapter `PlanetScale` is not compatible with the `postgres` provider specified in the schema. You should either load a Driver Adapter based on `postgres`, or update the `datasource` block in the schema to use the `mysql` provider instead.

In particular, one can check that adapter.flavour === 'mysql' (see code).

Edge case: Both postgresql and postgres are valid providers in the datasource block, but only postgres is a valid value for the flavour property of any DriverAdapter' class.


Prisma: 5.5.2

@jkomyno jkomyno added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: driverAdapters domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. labels Nov 9, 2023
@apolanc apolanc changed the title [Driver Adapters]: missing flavor/provider compatibility validation [Driver Adapters]: missing provider compatibility validation Jan 12, 2024
@apolanc
Copy link
Member

apolanc commented Jan 12, 2024

This item has been moved from Preview to GA

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. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. topic: driverAdapters topic: preview 👁
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants