#help me understand this error

4 messages · Page 1 of 1 (latest)

grave herald
#

Error:

4/25/2026, 5:55:07 PM [CONVEX M(deletionRequests:create)] Uncaught Error: Failed to insert or update a document in table "deletionRequest" because it does not match the schema: Found ID "k1734jgrja57n1ragc59w1qqjn85e196" from table `categoryParticipants`, which does not match the table name in validator `v.id("user")`.Path: .requestedBy
    at async handler (../convex/deletionRequests.ts:32:6)

mutation:

const create = mutation({
  args: {
    targetType: v.union(v.literal("player"), v.literal("playerPair")),
    targetId: v.string(),
    reason: v.string(),
  },
  handler: async (ctx, args) => {
    const user = await authComponent.safeGetAuthUser(ctx);
    if (!user) {
      throw new Error("Unauthorized");
    }

    // Check for existing pending request for this target
    const existing = await ctx.db
      .query("deletionRequest")
      .withIndex("by_target", (q) =>
        q.eq("targetType", args.targetType).eq("targetId", args.targetId),
      )
      .filter((q) => q.eq(q.field("status"), "pending"))
      .unique();

    if (existing) {
      throw new Error("A pending deletion request already exists for this item.");
    }

    const requestId = await ctx.db.insert("deletionRequest", {
      targetType: args.targetType,
      targetId: args.targetId,
      reason: args.reason,
      requestedBy: user._id,
      status: "pending",
      updatedAt: Date.now(),
    });

    return requestId;
  },
});```

tell me if you need any more context.
agile hedgeBOT
#

Hi @grave herald. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The error message tells you exactly what's happening:

Found ID "k1734jgrja57n1ragc59w1qqjn85e196" from table categoryParticipants, which does not match the table name in validator v.id("user"). Path: .requestedBy

Your schema defines requestedBy as v.id("user"), but user._id returned by authComponent.safeGetAuthUser(ctx) is actually an ID belonging to the categoryParticipants table — not the user table. Convex encodes the table name inside the ID itself, so the validator catches this mismatch at runtime. [Document IDs]

Why is this happening?

authComponent.safeGetAuthUser(ctx) is returning an object whose _id belongs to categoryParticipants, not user. This suggests you may be accidentally passing the wrong object — perhaps user is actually a categoryParticipants document, or the auth component is returning a joined/related document rather than the raw user.

What to check:

  1. Inspect what authComponent.safeGetAuthUser(ctx) actually returns. Log user to confirm its _id is from the user table and not from categoryParticipants.
  2. Check your schema for deletionRequest. Make sure requestedBy is defined as v.id("user") and that this matches the table the auth component actually stores users in.
  3. Cross-component ID issue: If your auth is a Convex component (like better-auth), note that v.id("user") validation does not work across component boundaries — you'd need to use v.string() instead for IDs coming from a component's tables. [Component boundary IDs]

Quick fix if using an auth component:

If user._id comes from a component's user table, change your schema field to v.string():

requestedBy: v.string(),
#

And store user._id as-is. You won't get the typed ID validation, but it will work across the component boundary.

If the auth component is supposed to return a first-class user table ID in your main app's scope, double-check that you're not accidentally using a categoryParticipants document as the user object somewhere in your code.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: