Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behaviour with onConflictDoUpdate #1393

Open
GregTheGreek opened this issue Jan 4, 2025 · 1 comment
Open

Inconsistent behaviour with onConflictDoUpdate #1393

GregTheGreek opened this issue Jan 4, 2025 · 1 comment

Comments

@GregTheGreek
Copy link

Version

0.8.10

Current behavior

Ran into an issue where onConflictDoUpdate did not do what was expected. I have two events, both which update the same table (removed a lot of code, and hid some fields). I noticed that I was always experiencing empty table values where the update should have worked, and appended the correct data if a row already existed that matched.

To solve this I had to change the onConflictDoUpdate to:

.onConflictDoUpdate((row) => {
  ...row,
  // update fields
});

Schema:

export const Transaction = onchainTable(
  "transaction", (t) => ({
  
    // from chain A event
    originChainId: t.integer(),
    depositId: t.integer(),
    destinationChainId: t.integer(),
    originTxHash,
    
    // from chain B event
    destinationTxHash: t.hex(),
  }),
  (table) => ({
    pk: primaryKey({ columns: [table.originChainId, table.depositId] })
  })
);

Processing logic:

ponder.on("event", async ({ event, context }) => {

  await context.db.insert(Transaction).values({
    depositId: Number(event.args.depositId),
    originChainId: context.network.chainId,

    // Non primary key fields
    originTxHash: event.transaction.hash,
  })
  .onConflictDoUpdate({
    originTxHash: event.transaction.hash,
  }));
});

ponder.on("event", async ({ event, context }) => {

  await context.db.insert(Transaction).values({
    depositId: event.args.depositId,
    originChainId: Number(event.args.originChainId),

    // Non primary key fields
    destinationTxHash: event.transaction.hash
  })
  .onConflictDoUpdate({
    destinationTxHash: event.transaction.hash
  }));
});

Expected behavior

No response

Steps to reproduce

No response

Link to repository

No response

Anything else?

No response

@kyscott18
Copy link
Collaborator

Hey, sorry about this issue. Have a few more questions:

  • when you say "experiencing empty table values where the update should have worked", do you mean that the row only contained the column that was updated after onConflictDoUpdate was used? Or the row was deleted from the table?
  • where are you noticing the bug (are you doing a find in a different indexing function?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants