bug: zrange rev flag causes empty return list / flaky zrange
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 595
- Forks
- 101
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 1
Description
Hi,
When using kv.zrange, the same input sometimes returns the list of values, and sometimes an empty list. When using the cli on Vercel, I always get the list.
export async function getChats(userId?: string | null) {
const session = await auth()
if (!userId) {
return []
}
if (userId !== session?.user?.id) {
return {
error: 'Unauthorized'
}
}
try {
const chats: string[] = await kv.zrange(`user:chat:${userId}`, 0, -1, {
rev: true
})
const pipeline = kv.pipeline()
for (const chat of chats) {
pipeline.hgetall(chat)
}
const results = await pipeline.exec()
return results as Chat[]
} catch (error) {
return []
}
}
I have used the debugger to make sure that the userId is the same in both cases and it passes the authentication check. However, chats sometimes evaluates to an empty list, when it should have the values I get using the cli. This is right below the line, so its not that there is an error thrown.
Not sure if this is an issue with the package or if I'm just unable to find out what the difference in the calls is when it works. In this case: is it possible to activate some sort of logging?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the kv.zrange call in getChats and compare its rev:true invocation with the CLI call that returns values. Trace the package's zrange request and available logging around this path, using the same userId and sorted-set key. Done means the cause of the inconsistent empty result is identified and zrange behaves consistently or reports the discrepancy clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100