From 85ecef9e305dcc72c3986c67d46dd3502db991e5 Mon Sep 17 00:00:00 2001 From: varasev <33550681+varasev@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:24:09 +0400 Subject: [PATCH] fix: Avoid key violation error in `Indexer.Fetcher.Optimism.TxnBatch` (#10752) * fix: Remove key violation error from Indexer.Fetcher.Optimism.TxnBatch fetcher * Update cspell.json --------- Co-authored-by: POA <33550681+poa@users.noreply.github.com> --- apps/indexer/lib/indexer/fetcher/optimism/txn_batch.ex | 10 +++++++++- cspell.json | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/indexer/lib/indexer/fetcher/optimism/txn_batch.ex b/apps/indexer/lib/indexer/fetcher/optimism/txn_batch.ex index c122d1713c..5f70a79f70 100644 --- a/apps/indexer/lib/indexer/fetcher/optimism/txn_batch.ex +++ b/apps/indexer/lib/indexer/fetcher/optimism/txn_batch.ex @@ -1265,7 +1265,15 @@ defmodule Indexer.Fetcher.Optimism.TxnBatch do |> Enum.uniq() |> Enum.filter(fn id -> id > 0 end) - Repo.delete_all(from(fs in FrameSequence, where: fs.id in ^ids)) + try do + Repo.delete_all(from(fs in FrameSequence, where: fs.id in ^ids)) + rescue + # we need to ignore `foreign_key_violation` exception when deleting the rows + # because there can be a case when the chain partially replaces the frame sequence + # (e.g. Unichain Private Testnet), and so some rows in `op_transaction_batches` table + # can still reference to the `op_frame_sequences` table + _ -> nil + end end defp set_frame_sequences_view_ready(sequences) do diff --git a/cspell.json b/cspell.json index 3fbe051f38..be5ffa2cca 100644 --- a/cspell.json +++ b/cspell.json @@ -564,6 +564,7 @@ "unfetched", "unfinalized", "unindexed", + "Unichain", "Unitarion", "Unitorius", "Unitorus",