FiberOpticFox
FiberOpticFox3mo ago

Paginated Query With Empty String Argument Gives Unexpected Results

I have a paginated query implemented something like this
const getDataByClerkId = query({
args: {
clerkId: v.string(),
utcTimestamp: v.number(),
paginationOpts: paginationOptsValidator,
},
handler: async (ctx, args) => {
ctx.db.query("TableName")
.withIndex("by_clerkId", (q) => q.eq("clerkId", args.clerkId))
.filter((q) => q.lte(q.field("_creationTime"), args.utcTimestamp))
.order("desc")
.paginate(args.paginationOpts)
}
})
const getDataByClerkId = query({
args: {
clerkId: v.string(),
utcTimestamp: v.number(),
paginationOpts: paginationOptsValidator,
},
handler: async (ctx, args) => {
ctx.db.query("TableName")
.withIndex("by_clerkId", (q) => q.eq("clerkId", args.clerkId))
.filter((q) => q.lte(q.field("_creationTime"), args.utcTimestamp))
.order("desc")
.paginate(args.paginationOpts)
}
})
and when argument to the query is { clerkId: "" }, it gives me back documents where the clerkId field is a non-empty string. I've noticed that it works fine when the argument is a non-empty string. So what's the deal with the empty string? I see this behaviour in my app, as well as running the function on convex dashboard. If you want more details of the specific convex instance, dm me.
6 Replies
Convex Bot
Convex Bot3mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
lee
lee3mo ago
that doesn't repro for me. can you give more details? i'm running this query
export const getDataByClerkId = query({
args: {
clerkId: v.string(),
utcTimestamp: v.number(),
paginationOpts: paginationOptsValidator,
},
handler: async (ctx, args) => {
const results = ctx.db.query("TableName")
.withIndex("by_clerkId", (q) => q.eq("clerkId", args.clerkId))
.filter((q) => q.lte(q.field("_creationTime"), args.utcTimestamp))
.order("desc")
.paginate(args.paginationOpts);
return results;
}
})
export const getDataByClerkId = query({
args: {
clerkId: v.string(),
utcTimestamp: v.number(),
paginationOpts: paginationOptsValidator,
},
handler: async (ctx, args) => {
const results = ctx.db.query("TableName")
.withIndex("by_clerkId", (q) => q.eq("clerkId", args.clerkId))
.filter((q) => q.lte(q.field("_creationTime"), args.utcTimestamp))
.order("desc")
.paginate(args.paginationOpts);
return results;
}
})
with arguments
{
clerkId: "",
paginationOpts: { cursor: null, numItems: 1 },
utcTimestamp: 1729091053000000,
}
{
clerkId: "",
paginationOpts: { cursor: null, numItems: 1 },
utcTimestamp: 1729091053000000,
}
where there's a document in the "TableName" table which has {clerkId: "yo"}
FiberOpticFox
FiberOpticFoxOP3mo ago
I guess it depends on the database instance. For example, I was not able to reproduce this in my own development instance, but was able to reproduce in production and in another developer's instance
lee
lee3mo ago
this sounds like a convex bug. if you could help us reproduce it, that would be very helpful
FiberOpticFox
FiberOpticFoxOP3mo ago
Can we take this into a non-public chat I can give more details there
lee
lee3mo ago
sure you can DM me or email support@convex.dev to wrap up here, the query was within a if (args.clerkId) { which is false for the empty string, so it was actually a different query that was running. phew

Did you find this page helpful?