ibrahimyaacob
ibrahimyaacob3w ago

DELETE_MISSING_KEY error on aggregate.trigger() on trigger (convex helper)

im trying to create a count aggregations on an existing table. i manage to run the migration as per below
export const backfillAggregatesMigration = migrations.define({
table: "socialPostComments",
customRange: (q) => q.withIndex("unreadStatus", (q) => q.eq("isRead", false)),
migrateOne: async (ctx, doc) => {
await unreadCommentCountByStatusTable.insertIfDoesNotExist(ctx, doc);
await unreadCommentCountByAssignedToTable.insertIfDoesNotExist(ctx, doc);
await unreadCommentCountByAccountTable.insertIfDoesNotExist(ctx, doc);
},
});
export const backfillAggregatesMigration = migrations.define({
table: "socialPostComments",
customRange: (q) => q.withIndex("unreadStatus", (q) => q.eq("isRead", false)),
migrateOne: async (ctx, doc) => {
await unreadCommentCountByStatusTable.insertIfDoesNotExist(ctx, doc);
await unreadCommentCountByAssignedToTable.insertIfDoesNotExist(ctx, doc);
await unreadCommentCountByAccountTable.insertIfDoesNotExist(ctx, doc);
},
});
and so far the backfill works fine. which i can see the aggregates count numbers are correct. but when i add the code to my trigger function (to update the triggers automatically).
export default async function socialPostCommentTriggers(
ctx: TriggerCtx,
triggerArgs: TriggerArgs<"socialPostComments">,
) {
const { newDoc, oldDoc, operation } = triggerArgs;

// testing triggers
const aggregateTriggerForStatus = unreadCommentCountByStatusTable.trigger();
const aggregateTriggerForAssignedTo =
unreadCommentCountByAssignedToTable.trigger();
const aggregateTriggerForAccount = unreadCommentCountByAccountTable.trigger();

await aggregateTriggerForStatus(ctx, triggerArgs);
await aggregateTriggerForAssignedTo(ctx, triggerArgs);
await aggregateTriggerForAccount(ctx, triggerArgs);
}
export default async function socialPostCommentTriggers(
ctx: TriggerCtx,
triggerArgs: TriggerArgs<"socialPostComments">,
) {
const { newDoc, oldDoc, operation } = triggerArgs;

// testing triggers
const aggregateTriggerForStatus = unreadCommentCountByStatusTable.trigger();
const aggregateTriggerForAssignedTo =
unreadCommentCountByAssignedToTable.trigger();
const aggregateTriggerForAccount = unreadCommentCountByAccountTable.trigger();

await aggregateTriggerForStatus(ctx, triggerArgs);
await aggregateTriggerForAssignedTo(ctx, triggerArgs);
await aggregateTriggerForAccount(ctx, triggerArgs);
}
i got the error above.
No description
20 Replies
Convex Bot
Convex Bot3w 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!
ibrahimyaacob
ibrahimyaacobOP3w ago
i could be using .idempotentTrigger(), but i feel like its not the right way to handle things
lee
lee3w ago
can you explain in detail how you did the migration
lee
lee3w ago
from what you describe, it sounds like you skipped step 1 here https://www.convex.dev/components/aggregate#attach-aggregate-to-an-existing-table
Convex
Aggregate
Keep track of sums and counts in a denormalized and scalable way.
ibrahimyaacob
ibrahimyaacobOP3w ago
hey i cant tell if thats making any difference because on my current dev env is stale (no changes happening in realtime) but let me try again
ibrahimyaacob
ibrahimyaacobOP3w ago
okay i run the backfill
No description
ibrahimyaacob
ibrahimyaacobOP3w ago
with this code in place
ibrahimyaacob
ibrahimyaacobOP3w ago
No description
ibrahimyaacob
ibrahimyaacobOP3w ago
im going to change from idempotentTrigger to just trigger
lee
lee3w ago
Convex
Aggregate
Keep track of sums and counts in a denormalized and scalable way.
lee
lee3w ago
if you did step 3 of the migration before step 1, your data is probably incorrect and you'll need to reset it
ibrahimyaacob
ibrahimyaacobOP3w ago
still getting this after mkaing the change
No description
lee
lee3w ago
yeah it sounds like your data is still out of sync
ibrahimyaacob
ibrahimyaacobOP3w ago
but i just ran the migration no i didnt
lee
lee3w ago
if your data is out of sync, you need to reset it first, then do the migration steps in order
ibrahimyaacob
ibrahimyaacobOP3w ago
okay here's the reset code
No description
ibrahimyaacob
ibrahimyaacobOP3w ago
i just run it now im migrating again @Lee on step 1-2, do i need to use idempotentTrigger() instead of trigger(). any difference ? @Lee it works!!! finally i can ship this can you help confirm this
lee
lee3w ago
step 1 says
Use insertIfDoesNotExist/replaceOrInsert/deleteIfExists in place of insert/replace/delete (or idempotentTrigger in place of trigger) to update items in the aggregate
ibrahimyaacob
ibrahimyaacobOP3w ago
hey @Lee im running the migration on prod but encountering an issue
[Request ID: 66c5943eafd14c49] Server Error
Uncaught Error: Uncaught Error: Too many bytes read in a single function execution (limit: 8388608 bytes). Consider using smaller limits in your queries, paginating your queries, or using indexed queries with a selective index range expressions.
[Request ID: 66c5943eafd14c49] Server Error
Uncaught Error: Uncaught Error: Too many bytes read in a single function execution (limit: 8388608 bytes). Consider using smaller limits in your queries, paginating your queries, or using indexed queries with a selective index range expressions.
oh i need to change the batch size my question now, if the migration fail, should i just continue or do need to reset the aggregates ?
lee
lee3w ago
as long as the idempotentTrigger is in place, you can just retry/continue the migration

Did you find this page helpful?