An error occurs if the orderBy array of findMany() contains an empty object
See original GitHub issueBug description
Following error occurs if the orderBy array of findMany() contains an empty object
Error:
Invalid `prisma.example.findMany()` invocation:
{
orderBy: [
{
createdAt: undefined
}
]
}
Unknown arg `0` in orderBy.0 for type ExampleOrderByInput. Available args:
type ExampleOrderByInput {
id?: SortOrder
createdAt?: SortOrder
}
How to reproduce
// ❌ Error
const examples = await prisma.example.findMany({
orderBy: [
{
createdAt: args.orderBy?.createdAt?.direction // 'asc' | 'desc' | undefined
}
]
})
// ❌ Error
const examples = await prisma.example.findMany({
orderBy: [
{
createdAt: undefined
}
]
})
// ❌ Error
const examples = await prisma.example.findMany({
orderBy: [
{
}
]
})
// ✅ Works
const examples = await prisma.example.findMany({
orderBy: {
createdAt: undefined
}
})
// ✅ Works
const examples = await prisma.example.findMany({
orderBy: [
]
})
// ✅ Works
const examples = await prisma.example.findMany({
orderBy: [
{
createdAt: args.orderBy?.createdAt?.direction // 'asc' | 'desc' | undefined
}
].filter((value) => !Object.values(value).includes(undefined))
})
Expected behavior
// ✅ Works
const examples = await prisma.example.findMany({
orderBy: [
{
createdAt: undefined
}
]
})
Prisma information
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "rhel-openssl-1.0.x"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Example {
/// The value of this field is generated by the database as: `uuid_generate_v4()`.
id String @id @default(dbgenerated())
createdAt DateTime @default(now())
}
Environment & setup
- OS: Amazon Linux on AWS Lambda
- Database: PostgreSQL on Amazon RDS
- Node.js version: 12.x
- Prisma version: 2.15.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Prisma Client API (Reference)
If you want the query to throw an error if the record is not found, then consider using ... Specifies which properties to...
Read more >Lodash orderBy returning empty array - Stack Overflow
It seems as if you are not actually calling orderBy() on the lodash object. Try the following code: JS const _ = require('lodash');...
Read more >Mongoose v6.8.1: API docs
[options] «Object» passed down to the MongoDB driver's connect() function, ... If bufferCommands is true, Mongoose will throw an error after bufferTimeoutMS ...
Read more >Query | GORM - GORM
errors.Is(result.Error, gorm.ErrRecordNotFound) ... When the destination object has a primary value, the primary key will be used to build the condition, ...
Read more >Model Querying - Finders - Sequelize
When group is provided, the findAndCountAll method returns an object with two properties: count - an array of objects - contains the count...
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
@matthewmueller I think you have mentioned the wrong person?
Thanks, @matthewmueller
Yes.