Skip to content

SDK returns incorrect value of count but data correctly filtered by range() and is() #1275

@taishikato

Description

@taishikato

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I tried to retrieve data from a table as follows.
I wanted to know the number of data filtered by range() and is().
However, the count value returns a value that ignores the range().
As a test, I set head to false and looked at the data in the return value, and it seems that the range filter is applied there (see the screenshot).

const input = req.params
const nullParams = input?.nullParams

let query = supabase
  .from('docs')
  .select('id', { count: 'exact', head: false })
  .match({
    user_id: user.id,
  })
  .order('created_at', { ascending: false })

if (nullParams && nullParams.length > 0) {
  for (const nullParam of nullParams) {
    // need to use .is() to filter data with null
    query = query.is(nullParam, null)
  }
}

if (input?.range) {
  query = query.range(input.range.from, input.range.to)
}

return await query

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '…'
  2. Click on '…'
  3. Scroll down to '…'
  4. See error

Expected behavior

The count value and the length of the data in the return value is the same.

Screenshots

CleanShot 2024-10-01 at 16 00 37@2x

System information

  • OS: macOS
  • Version of supabase-js: 2.39.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstale

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions