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

31 messages · Page 1 of 1 (latest)

fossil grove
#

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);
  },
});

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);
}

i got the error above.

charred vaporBOT
#

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](https://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!
fossil grove
#

i could be using .idempotentTrigger(), but i feel like its not the right way to handle things

glacial swallow
#

can you explain in detail how you did the migration

fossil grove
#

hey

fossil grove
#

but let me try again

#

okay i run the backfill

#

with this code in place

#

im going to change from idempotentTrigger to just trigger

glacial swallow
#

if you did step 3 of the migration before step 1, your data is probably incorrect and you'll need to reset it

fossil grove
#

still getting this after mkaing the change

glacial swallow
#

yeah it sounds like your data is still out of sync

fossil grove
glacial swallow
#

if your data is out of sync, you need to reset it first, then do the migration steps in order

fossil grove
#

okay here's the reset code

#

i just run it

#

now im migrating again

fossil grove
# fossil grove

@glacial swallow on step 1-2, do i need to use idempotentTrigger() instead of trigger(). any difference ?

#

@glacial swallow it works!!!

#

finally i can ship this

glacial swallow
fossil grove
#

hey @glacial swallow 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.
#

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 ?