Rune DarkfireR
Convex Community17mo ago
2 replies
Rune Darkfire

Optional validator in mutation not working for one attribute but fine for others

I'm not sure what I'm doing wrong on this mutation, I consistently get an error on the logoStorageId when I am calling it when the value is null. None of the other optional validators are giving me grief, just this one :
export const update = mutation({
  args: {
    id: v.id("vendors"),
    name: v.optional(v.string()),
    category: v.optional(v.string()),
    contactPerson: v.optional(v.string()),
    email: v.optional(v.string()),
    phone: v.optional(v.string()),
    address: v.optional(v.string()),
    website: v.optional(v.string()),
    description: v.optional(v.string()),
    status: v.optional(v.string()),
    riskScore: v.optional(v.number()),
    totalSpend: v.optional(v.number()),
    performance: v.optional(v.number()),
    logoStorageId: v.optional(v.id("_storage")),
  },
  handler: async (ctx, args) => {
    const { id, ...fields } = args

    if (args.logoStorageId) {
      const vendor = await ctx.db.get(args.id);

      if (vendor?.logoStorageId) {
        await ctx.storage.delete(vendor.logoStorageId)
      }
    }
    await ctx.db.patch(id, {
      ...fields,
      updatedAt: Date.now(),
    })
  },
})
This is the error, it's behaving as if it's not optional for some reason :
[CONVEX M(vendors:update)] [Request ID: f176b6cccf8b730e] Server Error
ArgumentValidationError: Value does not match validator.
Path: .logoStorageId
Value: null
Validator: v.id("_storage")
Because there's no way to actually step through this code (is there??) I can't actually see where precisely it is going wrong. Any help would be appreciated - thank you!
Was this page helpful?