{"record":{"id":"68217c373c99e0cb","repo":"nautechsystems/nautilus_trader","slug":"failed-to-insert-into-execution-transaction-table","errorCode":null,"errorMessage":"Failed to insert into execution_transaction table: {e}","messagePattern":"Failed to insert into execution_transaction table: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":3331,"sourceCode":"            ON CONFLICT (chain_id, transaction_hash)\n            DO UPDATE SET transaction_hash = EXCLUDED.transaction_hash\n            WHERE execution_transaction.wallet_address = EXCLUDED.wallet_address\n              AND execution_transaction.nonce = EXCLUDED.nonce\n              AND execution_transaction.purpose = EXCLUDED.purpose\n              AND execution_transaction.status = EXCLUDED.status\n              AND execution_transaction.client_order_id IS NOT DISTINCT FROM EXCLUDED.client_order_id\n        \",\n        )\n        .bind(chain_id as i32)\n        .bind(wallet_address)\n        .bind(nonce as i64)\n        .bind(transaction_hash)\n        .bind(purpose)\n        .bind(status)\n        .bind(client_order_id)\n        .execute(&self.pool)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to insert into execution_transaction table: {e}\"))?;\n\n        anyhow::ensure!(\n            result.rows_affected() == 1,\n            \"Execution transaction {transaction_hash} conflicts with its persisted record\"\n        );\n        Ok(())\n    }\n\n    /// Installs execution schema version 2 without changing existing transaction rows.\n    ///\n    /// The migration locks the legacy transaction table, refuses unresolved version 1 rows,\n    /// installs the versioned intent and hash-history tables, and fences older writers before\n    /// releasing the lock. This prevents a mixed-version process from bypassing the new signer\n    /// ownership constraints.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database operation fails.","sourceCodeStart":3313,"sourceCodeEnd":3349,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L3313-L3349","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n.map_err(|e| anyhow::anyhow!(\"Failed to insert into execution_transaction table: {e}\"))?;\n// after\n.map_err(|e| {\n    tracing::error!(error = %e, %transaction_hash, \"execution_transaction insert failed\");\n    anyhow::anyhow!(\"Failed to insert into execution_transaction table: {e}\")\n})?;","handlingStrategy":"try-catch","validationCode":"let exists = sqlx::query(\"SELECT to_regclass('execution_transaction') IS NOT NULL\")\n    .fetch_one(&pool).await?;\nif !exists.get::<_, bool>(0) { anyhow::bail!(\"execution_transaction table missing; run ensure_execution_transaction_schema\"); }","typeGuard":null,"tryCatchPattern":"match insert_execution_transaction(...).await {\n    Ok(()) => (),\n    Err(e) if e.to_string().contains(\"duplicate key\") => handle_conflict(),\n    Err(e) => return Err(e),\n}","preventionTips":["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"],"tags":["database","sqlx","insert"],"backgroundTag":"database-write-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}