nautechsystems/nautilus_trader · error · anyhow::Error
Failed to insert into execution_transaction table
Error message
Failed to insert into execution_transaction table: {e} What it means
This error wraps any failure inserting an execution transaction record into the `executionTransaction` table via sqlx `execute`. The library throws it to add context that the specific persistence write for an execution transaction failed.
Solutions
- Call ensure_execution_transaction_schema before inserts so the table and columns exist
- Check the inner `{e}` for constraint violation names (e.g. duplicate key)
- Use upsert (ON CONFLICT) if duplicate transaction hashes are expected
- Verify DB connectivity and that transaction_hash/purpose/status values fit column types/lengths
Example fix
// before
.map_err(|e| anyhow::anyhow!("Failed to insert into execution_transaction table: {e}"))?;
// after
.map_err(|e| {
tracing::error!(error = %e, %transaction_hash, "execution_transaction insert failed");
anyhow::anyhow!("Failed to insert into execution_transaction table: {e}")
})?; Defensive patterns
Strategy: try-catch
Validate before calling
let exists = sqlx::query("SELECT to_regclass('execution_transaction') IS NOT NULL")
.fetch_one(&pool).await?;
if !exists.get::<_, bool>(0) { anyhow::bail!("execution_transaction table missing; run ensure_execution_transaction_schema"); } Try / catch
match insert_execution_transaction(...).await {
Ok(()) => (),
Err(e) if e.to_string().contains("duplicate key") => handle_conflict(),
Err(e) => return Err(e),
} Prevention
- Always call ensure_execution_transaction_schema before inserts
- Make inserts idempotent with ON CONFLICT for transaction_hash
- Validate non-null fields (status, purpose, client_order_id) before binding
When it happens
Trigger: Calling the execution transaction insert when the table does not exist (migration not run), a NOT NULL/UNIQUE constraint is violated (duplicate transaction hash or missing client_order_id), the connection pool is down, or a bind type mismatches the column type.
Common situations: Deploying against a database before ensure_execution_transaction_schema ran; inserting the same transaction_hash twice without conflict handling; Postgres out of disk or connection limit reached.
Related errors
- Failed to batch insert into block table
- Failed to batch insert into pool_event_block table
- Failed to batch insert into pool_liquidity_event table
- Failed to batch insert into pool_swap_event table
- Failed to batch insert into pool table
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/68217c373c99e0cb.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/blockchain/src/cache/database.rs:3331
ON CONFLICT (chain_id, transaction_hash)
DO UPDATE SET transaction_hash = EXCLUDED.transaction_hash
WHERE execution_transaction.wallet_address = EXCLUDED.wallet_address
AND execution_transaction.nonce = EXCLUDED.nonce
AND execution_transaction.purpose = EXCLUDED.purpose
AND execution_transaction.status = EXCLUDED.status
AND execution_transaction.client_order_id IS NOT DISTINCT FROM EXCLUDED.client_order_id
",
)
.bind(chain_id as i32)
.bind(wallet_address)
.bind(nonce as i64)
.bind(transaction_hash)
.bind(purpose)
.bind(status)
.bind(client_order_id)
.execute(&self.pool)
.await
.map_err(|e| anyhow::anyhow!("Failed to insert into execution_transaction table: {e}"))?;
anyhow::ensure!(
result.rows_affected() == 1,
"Execution transaction {transaction_hash} conflicts with its persisted record"
);
Ok(())
}
/// Installs execution schema version 2 without changing existing transaction rows.
///
/// The migration locks the legacy transaction table, refuses unresolved version 1 rows,
/// installs the versioned intent and hash-history tables, and fences older writers before
/// releasing the lock. This prevents a mixed-version process from bypassing the new signer
/// ownership constraints.
///
/// # Errors
///
/// Returns an error if the database operation fails.View on GitHub (pinned to 18893faf8b)