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

[Bug] Getting UniqueConstraintError when using Schema.upsert #1047

Closed
benbaessler opened this issue Aug 18, 2024 · 2 comments · Fixed by #1177
Closed

[Bug] Getting UniqueConstraintError when using Schema.upsert #1047

benbaessler opened this issue Aug 18, 2024 · 2 comments · Fixed by #1177

Comments

@benbaessler
Copy link

In my deployment logs on Railway I'm getting this error when starting the application.

Failed 'User.upsert' database method with non-retryable error: UNIQUE constraint failed: User.id
UniqueConstraintError: UNIQUE constraint failed: User.id

This is the code that caused it:

let reqs = [
  User.upsert({
	  id: `${event.args.buyer.toLowerCase()}:${event.args.castHash}`,
	  create: {
		  ticketBalance: event.args.amount,
		  referralFeesEarned: 0n,
		  creatorFeesEarned: 0n,
	  },
	  update: ({ current }) => ({
		  ticketBalance: current.ticketBalance + event.args.amount,
	  }),
  }),
  User.upsert({
	  id: `${event.args.castCreator.toLowerCase()}:${event.args.castHash}`,
	  create: {
		  ticketBalance: 0n,
		  referralFeesEarned: 0n,
		  creatorFeesEarned: feeAmount,
	  },
	  update: ({ current }) => ({
		  creatorFeesEarned: current.creatorFeesEarned + feeAmount,
	  }),
  }),
  // some more requests  
]

await Promise.all(reqs)

The issue came up when I redeployed the project due to an unrelated change.

@benbaessler benbaessler changed the title Getting UniqueConstraintError when using Schema.upsert [Bug] Getting UniqueConstraintError when using Schema.upsert Aug 19, 2024
@0xOlias
Copy link
Collaborator

0xOlias commented Sep 4, 2024

Thanks for the bug report, this indeed looks like an edge case within Ponder. Working on a fix. Do you know if this occurred during historical or realtime indexing?

@0xOlias
Copy link
Collaborator

0xOlias commented Sep 11, 2024

Bump on this @benbaessler - I was able to reproduce and fix this issue in realtime, but not in historical (#1072). If you can confirm that this happened while handling a new live event (not a historical event), I'll merge that and consider this completed.

@kyscott18 kyscott18 mentioned this issue Oct 21, 2024
@kyscott18 kyscott18 linked a pull request Oct 21, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from Todo to Done in Ponder Roadmap Nov 8, 2024
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

Successfully merging a pull request may close this issue.

2 participants