groupBy is not usable with $transaction
See original GitHub issueBug description
Trying to use the unawaited return value of a prisma.<type>.groupBy(…) in a prisma.$transaction([…]) will result in a typescript Type error:
Type 'GetOrderGroupByPayload<{ by: "vendorId"[]; _sum: { price: true; }; }>' is not assignable to type 'PrismaPromise<any>'.
Property '[prisma]' is missing in type 'Promise<(PickArray<OrderGroupByOutputType, "vendorId"[]> & { _sum: { price: number | null; }; })[]>' but required in type '{ [prisma]: true; }'
It seems that all values passed into $transaction must have a property with a Symbol called prisma set to true. This is not the case for groupBy, but works for other queries/mutate actions like findMany, deleteMany, findUnique, …
How to reproduce
Using below minimal demo schema, this code errors:
await db.$transaction([
db.order.groupBy({
by: ["vendorId"],
_sum: {
price: true,
}
})
])
Expected behavior
$transaction should properly accept groupBy queries, running them as a transaction with other queries.
Prisma information
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Vendor {
id Int @id
Orders Order[]
}
model Order {
id Int @id
price Float
Vendor Vendor @relation(fields: [vendorId], references: [id])
vendorId Int
}
Environment & setup
- OS: Windows 10
- Database: MySQL
- Node.js version: v14.15.4
- Typescript version: Version 4.3.2
Prisma Version
prisma : 2.25.0
@prisma/client : 2.25.0
Current platform : windows
Query Engine : query-engine c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine : migration-engine-cli c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : c838e79f39885bc8e1611849b1eb28b5bb5bc922
Studio : 0.402.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Client side GroupBy is not supported - Stack Overflow
NetStandard 2.0 to keep working. It's not logical to block a working feature. OK, it penalises performance, but I know and I need...
Read more >Group by function not working correctly in SQL server CTE
Here I want to group totalcount based on Sdate and Transaction Type. But it is not working correctly. I have 3 records with...
Read more >Group by drop down not working on some client accounts
I want you to know that I'm here to provide some steps to get Group by dropdown working. It could be that you're...
Read more >Group On not working for GL transaction - eOne Solutions
I am attempting to integrate GL transactions with SmartConnect, but appear to be having some trouble with the Group On functionality.
Read more >Common error in Group By - GeeksforGeeks
Error: Column 'col' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can confirm this, looks like we forgot to use
PrismaPromise
type which we use to make sure people only pass prisma client calls to$transaction
.cc @millsp
Call actually works fine so disable typechecking using
//@ts-ignore
for now while we fix this.See https://github.com/prisma/docs/issues/800 (it’s only mentioned once in the docs)