Prisma 6.9.0 error [DataMapperError]: Missing data field on query with @map("snake_case") attribute
Bug description
When querying a model that uses the @map attribute to map a snake_case database column to a camelCase model field, Prisma's data mapper incorrectly fails to find the field in the result set.
The generated SQL query correctly uses an alias (e.g., SELECT "column_name" AS "columnName"). The data returned from the database driver also correctly contains the aliased camelCase key. However, the final data mapping layer still seems to search for the original snake_case key, causing a DataMapperError: Missing data field error.
Severity
🚨 Critical: Data loss, app crash, security issue
Reproduction
How to Reproduce
- Define the following generic schema in prisma/schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model BlogPost {
id Int @id @default(autoincrement())
title String @unique
publishedAt DateTime? @map("published_at")
@@map("blog_posts")
}
-
Run prisma db push to sync the schema with the database.
-
Run the following TypeScript code to query the data:
import { PrismaClient } from '@prisma/client';
import { PrismaPg } from '@prisma/adapter-pg'
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL })
const prisma = new PrismaClient({ adapter })
async function main() {
// Seed some data first
const postTitle = 'Hello World';
await prisma.blogPost.create({
data: {
title: postTitle,
publishedAt: new Date(),
},
});
// This is the query that fails
try {
const post = await prisma.blogPost.findUnique({
where: {
title: postTitle,
},
});
console.log('Found post:', post);
} catch (error) {
console.error('An error occurred:', error);
} finally {
await prisma.$disconnect();
}
}
main();
- Observe the error in the console.
Expected vs. Actual Behavior
Expected behavior
The query should successfully execute and return the BlogPost object. The program should log something similar to:
Found post: { id: 1, title: 'Hello World', publishedAt: 2025-06-16T08:38:00.000Z }
Actual behavior
The query fails with a DataMapperError. The logs would show the following pattern (adapted for this new example):
prisma:query SELECT "t0"."id", "t0"."title", "t0"."published_at" AS "publishedAt" FROM "public"."blog_posts" AS "t0" WHERE "t0"."title" = $1 LIMIT $2
prisma:error Missing data field (Value): 'published_at'; node: {"type":"Value","dbName":"published_at","resultType":{"type":"DateTime"}}; data: {"id":1, "title": "Hello World", "publishedAt":"2025-06-16T08:38:00.000+00:00"}
prisma:query ROLLBACK
An error occurred: [DataMapperError]: Missing data field (Value): 'published_at'; node: {"type":"Value","dbName":"published_at","resultType":{"type":"DateTime"}}; data: {"id":1, "title": "Hello World", "publishedAt":"2025-06-16T08:38:00.000+00:00"}
Frequency
Consistently reproducible
Does this occur in development or production?
Both development and production
Is this a regression?
Yes, last worked in Prisma 6.6.0, broke in 6.9.0
Workaround
Revert upgrade to 6.6.0
Prisma Schema & Queries
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model BlogPost {
id Int @id @default(autoincrement())
title String @unique
publishedAt DateTime? @map("published_at")
@@map("blog_posts")
}
import { PrismaClient } from '@prisma/client';
import { PrismaPg } from '@prisma/adapter-pg'
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL })
const prisma = new PrismaClient({ adapter })
async function main() {
// Seed some data first
const postTitle = 'Hello World';
await prisma.blogPost.create({
data: {
title: postTitle,
publishedAt: new Date(),
},
});
// This is the query that fails
try {
const post = await prisma.blogPost.findUnique({
where: {
title: postTitle,
},
});
console.log('Found post:', post);
} catch (error) {
console.error('An error occurred:', error);
} finally {
await prisma.$disconnect();
}
}
main();
Prisma Config
No response
Logs & Debug Info
prisma:query SELECT "t0"."id", "t0"."title", "t0"."published_at" AS "publishedAt" FROM "public"."blog_posts" AS "t0" WHERE "t0"."title" = $1 LIMIT $2
prisma:error Missing data field (Value): 'published_at'; node: {"type":"Value","dbName":"published_at","resultType":{"type":"DateTime"}}; data: {"id":1, "title": "Hello World", "publishedAt":"2025-06-16T08:38:00.000+00:00"}
prisma:query ROLLBACK
An error occurred: [DataMapperError]: Missing data field (Value): 'published_at'; node: {"type":"Value","dbName":"published_at","resultType":{"type":"DateTime"}}; data: {"id":1, "title": "Hello World", "publishedAt":"2025-06-16T08:38:00.000+00:00"}
Environment & Setup
- OS: macOs
- Database: PostgreSQL
- Node.js version: v20.12.2
Prisma Version
Environment variables loaded from .env
Prisma schema loaded from src/infrastructures/database/prisma/schema
prisma : 6.9.0
@prisma/client : 6.9.0
Computed binaryTarget : darwin
Operating System : darwin
Architecture : x64
Node.js : v20.12.2
TypeScript : 5.8.3
Query Engine (Node-API) : libquery-engine 81e4af48011447c3cc503a190e86995b66d2a28e (at node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Schema Engine : schema-engine-cli 81e4af48011447c3cc503a190e86995b66d2a28e (at node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/schema-engine-darwin)
Schema Wasm : @prisma/prisma-schema-wasm 6.9.0-10.81e4af48011447c3cc503a190e86995b66d2a28e
Default Engines Hash : 81e4af48011447c3cc503a190e86995b66d2a28e
Studio : 0.511.0