question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

An error occurs if the orderBy array of findMany() contains an empty object

See original GitHub issue

Bug 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:open
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kennhungcommented, Jun 1, 2021

@matthewmueller I think you have mentioned the wrong person?

0reactions
kensukesaitocommented, Oct 6, 2021

Thanks, @matthewmueller

Perhaps a filter pattern where created_at can be provided or undefined, depending on what the user chooses?

Yes.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found