gegi
gegi4w ago

Heyo, Im getting an error after clearing

Heyo, Im getting an error after clearing my episodes table and adding items to a different table:
Found ID "jx710mhbsdtz4dyz175vfvna717shz3d" from table episodes
Seems like convex assumes the id is still taken by an episode? How can I fix it
8 Replies
Sara
Sara4w ago
do you mind showing your schema? particularly if there's any other table that relates to this deleted table? I'm thinking that you may have kept some data that have a relationship with this table by using "v.id("episodes")", in which the table is cleared, but the id somewhere else still exists, in which you will need to remove it
gegi
gegiOP4w ago
I do have relations for it, but I actually cleared all my tables
Sara
Sara4w ago
thats odd. I don't know :joeshrug:
erquhart
erquhart4w ago
Can you share the function where this error is happening
gegi
gegiOP4w ago
export const updateSubscription = internalMutation({
args: {
userId: v.id("user"), // better auth component user table
subscriptionId: v.string(),
productId: v.string(),
status: v.union(
v.literal("active"),
v.literal("suspended"),
v.literal("terminated"),
v.literal("finished"),
),
plan: v.union(v.literal("basic"), v.literal("pro")),
},
handler: async (ctx, { userId, subscriptionId, productId, status, plan }) => {
const existing = await ctx.db
.query("subscriptions")
.withIndex("by_userId", (q) => q.eq("userId", userId))
.first();

if (existing) {
await ctx.db.patch(existing._id, {
subscriptionId,
productId,
status,
plan,
});
} else {
await ctx.db.insert("subscriptions", {
userId,
subscriptionId,
productId,
status,
plan,
});
}
},
});
export const updateSubscription = internalMutation({
args: {
userId: v.id("user"), // better auth component user table
subscriptionId: v.string(),
productId: v.string(),
status: v.union(
v.literal("active"),
v.literal("suspended"),
v.literal("terminated"),
v.literal("finished"),
),
plan: v.union(v.literal("basic"), v.literal("pro")),
},
handler: async (ctx, { userId, subscriptionId, productId, status, plan }) => {
const existing = await ctx.db
.query("subscriptions")
.withIndex("by_userId", (q) => q.eq("userId", userId))
.first();

if (existing) {
await ctx.db.patch(existing._id, {
subscriptionId,
productId,
status,
plan,
});
} else {
await ctx.db.insert("subscriptions", {
userId,
subscriptionId,
productId,
status,
plan,
});
}
},
});
erquhart
erquhart4w ago
Do you have a stack trace for where in the handler this error is coming from, otherwise you'll need to console log to narrow it down. You want to see exactly when execution fails.
gegi
gegiOP4w ago
It comes from my http api I do a mutation on a http.route when I receive webhook
erquhart
erquhart4w ago
Right, but inside of this internal mutation that error is occurring, we need to know which function in this mutation is causing the error If you add console logs throughout the mutation, you can deduce where the failure is occurring

Did you find this page helpful?