supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

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

Open taishikato opened this issue 1 year ago • 1 comments

Bug report

  • [x] I confirm this is a bug with Supabase, not with my own application.
  • [x] 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

taishikato avatar Oct 01 '24 07:10 taishikato