-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Multiple Prisma Clients with Different Adapters (PostgreSQL + MySQL) Fail in Same Process with Rust-Free Client #28221
Description
Bug description
When using two separate Prisma clients with different database adapters (PostgreSQL via @prisma/adapter-pg and MySQL via @prisma/adapter-mariadb) in the same Node.js process, the second client call fails with a deserialization error suggesting the rust-free client is incorrectly reusing state from the first client's adapter type.
Both clients use the new rust-free client configuration (engineType = "client"). The first query to the PostgreSQL client works fine, but any subsequent query to the MySQL client fails with:
Error: unknown variant `mysql`, expected `postgres`
This suggests there's shared state or deserialization logic that doesn't properly handle multiple adapter types in the same process.
Severity
🚨 Critical: Data loss, app crash, security issue
Reproduction
Step 1: Generate Two Prisma Clients
PostgreSQL Schema (prisma/postgres/schema.prisma):
generator client {
provider = "prisma-client"
output = "../../generated/postgres-client"
engineType = "client"
moduleFormat = "cjs"
runtime = "nodejs"
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String
}MySQL Schema (prisma/mysql/schema.prisma):
generator client {
provider = "prisma-client"
output = "../../generated/mysql-client"
engineType = "client"
moduleFormat = "cjs"
runtime = "nodejs"
}
datasource db {
provider = "mysql"
url = env("MYSQL_DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String
}Run npx prisma generate for both schemas.
Step 2: Initialize Both Clients with Adapters
File: database.ts
import { PrismaClient as PostgresClient } from "./generated/postgres-client";
import { PrismaClient as MySQLClient } from "./generated/mysql-client";
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaMariaDb } from "@prisma/adapter-mariadb";
import { Pool } from "pg";
// PostgreSQL client
const postgresClient = new PostgresClient({
adapter: new PrismaPg(
new Pool({
connectionString: process.env.POSTGRES_DATABASE_URL,
}),
{
schema: "public",
},
),
});
// MySQL client
const mysqlUrl = new URL(process.env.MYSQL_DATABASE_URL);
const mysqlClient = new MySQLClient({
adapter: new PrismaMariaDb({
host: mysqlUrl.hostname,
user: mysqlUrl.username,
password: mysqlUrl.password,
database: mysqlUrl.pathname.slice(1),
port: Number(mysqlUrl.port),
}),
});
export { postgresClient, mysqlClient };Step 3: Execute Queries on Both Clients
File: reproduce-issue.ts
import { postgresClient, mysqlClient } from "./database";
async function main() {
// First query to PostgreSQL - works fine
const postgresData = await postgresClient.user.findFirst();
console.log("PostgreSQL query succeeded:", postgresData);
// Second query to MySQL - fails with error
const mysqlData = await mysqlClient.user.findFirst();
console.log("MySQL query succeeded:", mysqlData);
}
main().catch(console.error);Step 4: Run the Script
node reproduce-issue.tsExpected vs. Actual Behavior
Expected Behavior
Both Prisma clients should work independently in the same process. The PostgreSQL query should execute successfully, followed by the MySQL query executing successfully, allowing applications to query multiple databases with different providers.
Expected output:
PostgreSQL query succeeded: { id: 1, email: 'user@example.com', name: 'John' }
MySQL query succeeded: { id: 1, email: 'admin@example.com', name: 'Admin' }
Actual Behavior
The first query to PostgreSQL succeeds, but the second query to MySQL fails with a deserialization error:
PostgreSQL query succeeded: { id: 1, email: 'user@example.com', name: 'John' }
Error: unknown variant `mysql`, expected `postgres`
The error suggests that the rust-free client's internal state is incorrectly using the PostgreSQL adapter's type when attempting to deserialize or process the MySQL client's operations.
Frequency
Consistently reproducible
Does this occur in development or production?
Both development and production
Is this a regression?
Unknown - this is the first time attempting to use multiple Prisma clients with different adapters in the same process with the rust-free client. This configuration may not have been tested or supported in previous versions.
Workaround
Reveting to the rust client
Prisma Schema & Queries
PostgreSQL Schema (prisma/postgres/schema.prisma)
generator client {
provider = "prisma-client"
output = "../../generated/postgres-client"
engineType = "client"
moduleFormat = "cjs"
runtime = "nodejs"
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String
}MySQL Schema (prisma/mysql/schema.prisma)
generator client {
provider = "prisma-client"
output = "../../generated/mysql-client"
engineType = "client"
moduleFormat = "cjs"
runtime = "nodejs"
}
datasource db {
provider = "mysql"
url = env("MYSQL_DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String
}Queries
// PostgreSQL query - succeeds
await postgresClient.user.findFirst();
// MySQL query - fails
await mysqlClient.user.findFirst();Prisma Config
Both schemas use identical generator configuration:
generator client {
provider = "prisma-client"
output = "[different output paths]"
engineType = "client" // Rust-free client
moduleFormat = "cjs"
runtime = "nodejs"
}Key configuration details:
engineType = "client"- Using the new rust-free client (WASM-based)moduleFormat = "cjs"- CommonJS module formatruntime = "nodejs"- Node.js runtime- Separate output directories for each client
Logs & Debug Info
Error Message
Error: unknown variant `mysql`, expected `postgres`
Environment & Setup
- OS: Linux (WSL2)
- Node.js version: v22.10.0
Prisma Version
prisma : 6.16.3
@prisma/client : 6.16.3
@prisma/adapter-pg : 6.16.3
@prisma/adapter-mariadb : 6.16.3