Giovani GranzottoG
Convex Communityβ€’2y agoβ€’
3 replies
Giovani Granzotto

Confusing errors on db.patch calls inside mutation

Hi, I'm making some changes to handle a new webhook event and started seeing errors when my mutation is called. The errors complain about missing required fields when calling db.patch:

Uncaught Error: Failed to insert or update a document in table "externalPayment" because it does not match the schema: Object is missing the required field `status`. Consider wrapping the field validator in `v.optional(...)` if this is expected.


However, I was under the impression that all fields are optional on db.patch (it will update only the received ones), as is hinted by the method signature expecting the "partial" object:
.patch<"externalPayment">(id: Id<"externalPayment">, value: Partial<{
    _id: Id<"externalPayment">;
    _creationTime: number;
    paymentId?: string | undefined;
    ticketId: string;
    method: string;
    amount: number;
    tip: number;
    status: string;


and so a "required field" validation against the schema doesn't really make sense.

However, this is behaving inconsistently, as shown in the attached screenshots. As it was working properly before today, I suspect that the real culprit might be the multiple mutations running in parallel, since I also got this error once:

Documents read from or written to the "externalPayment" table changed while this mutation was being run and on every subsequent retry. Another call to this mutation changed the document with ID "jx72sxepckwzjjbq6be4fec1en6xm7e9". See https://docs.convex.dev/error#1


So why am I seeing the schema validation errors? Are these two related? I'll work to fix the concurrency issue regardless, but it took me a while to get the concurrency error so if it is the real cause it would have been better to have seen this first. Am I missing anything? I will appreciate any help.
image.png
image.png
Was this page helpful?