{"record":{"id":"05fd4a08070ec4d1","repo":"nautechsystems/nautilus_trader","slug":"failed-to-reconstruct-migrated-hash-e","errorCode":null,"errorMessage":"Failed to reconstruct migrated hash: {e}","messagePattern":"Failed to reconstruct migrated hash: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":4273,"sourceCode":"                            UPDATE execution_transaction_hash\n                            SET status = $3, block_number = $4, block_hash = $5,\n                                receipt_success = $6, gas_used = $7,\n                                effective_gas_price = $8, updated_at = NOW()\n                            WHERE intent_id = $1 AND transaction_hash = $2 AND current\n                              AND payload_expected\n                            \",\n                        )\n                        .bind(record.intent_id)\n                        .bind(transaction_hash)\n                        .bind(status.as_str())\n                        .bind(block_number)\n                        .bind(block_hash)\n                        .bind(receipt_success)\n                        .bind(gas_used)\n                        .bind(record.effective_gas_price.as_deref())\n                        .execute(&mut *transaction)\n                        .await\n                        .map_err(|e| anyhow::anyhow!(\"Failed to reconstruct migrated hash: {e}\"))?;\n                        anyhow::ensure!(\n                            hash_result.rows_affected() == 1,\n                            \"Migrated terminal transaction hash was not found\"\n                        );\n                        sqlx::query(\n                            \"UPDATE execution_intent SET status = $2, updated_at = NOW() WHERE id = $1\",\n                        )\n                        .bind(record.intent_id)\n                        .bind(status.as_str())\n                        .execute(&mut *transaction)\n                        .await\n                        .map_err(|e| anyhow::anyhow!(\"Failed to reconstruct migrated intent: {e}\"))?;\n                        if current_status != status.as_str() {\n                            sqlx::query(\n                                \"\n                                INSERT INTO execution_transaction_transition (\n                                    intent_id, transaction_hash_id, transition_key,\n                                    from_status, to_status, block_number, block_hash","sourceCodeStart":4255,"sourceCodeEnd":4291,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L4255-L4291","documentation":"This error wraps sqlx failures from the UPDATE of execution_transaction_hash that reconstructs a migrated terminal transaction hash (status, block number/hash, receipt_success, gas_used, effective_gas_price). It fires only when the UPDATE statement errors at the database level; the separate 'Migrated terminal transaction hash was not found' error covers the zero-rows-affected case. The driver error is interpolated as {e}.","triggerScenarios":"The UPDATE `... WHERE intent_id = $1 AND transaction_hash = $2 AND current AND payload_expected` fails due to: type/column mismatches (e.g. effective_gas_price string not castable to the target NUMERIC column), i64 out-of-range values for block_number/gas_used, CHECK/FK constraint violations, a lost DB connection mid-transaction, or concurrent DDL/schema drift.","commonSituations":"Migration evidence whose effective_gas_price does not parse into the target column; block numbers or gas values exceeding column range; migration run against a database whose schema predates a required column; connection timeouts during a long-running migration batch.","solutions":["Read the interpolated {e} to identify the failing column or constraint and fix the offending migration record field.","Verify the target schema matches the migration's expectations (execution_transaction_hash columns: status, block_number, block_hash, receipt_success, gas_used, effective_gas_price).","Confirm numeric fields fit their column types (BIGINT bounds for block_number/gas_used) and price strings parse as NUMERIC before migrating.","Re-run the migration if the error was transient (connection drop); the transaction rollback preserves consistency.","Check the DB server logs at the failure time for constraint or serialization details."],"exampleFix":"// before: binding unvalidated values\n.bind(record.effective_gas_price.as_deref())\n\n// after: validate before executing\nlet price = record.effective_gas_price.as_deref()\n    .map(|p| p.parse::<rust_decimal::Decimal>())\n    .transpose()\n    .context(\"invalid effective_gas_price in migration record\")?;\n.bind(price)","handlingStrategy":"validation","validationCode":"// before migrating, confirm the hash row is updatable and values fit columns\nlet row = sqlx::query_scalar::<_, i64>(\n    \"SELECT COUNT(*) FROM execution_transaction_hash \\\n     WHERE intent_id = $1 AND transaction_hash = $2 AND current AND payload_expected\",\n).bind(&record.intent_id).bind(&record.transaction_hash)\n .fetch_one(&pool).await?;\nanyhow::ensure!(row == 1, \"hash row not updatable for intent {}\", record.intent_id);","typeGuard":"fn hash_fields_in_range(record: &MigrationRecord) -> bool {\n    record.block_number.map_or(false, |b| i64::try_from(b).is_ok())\n        && record.gas_used.map_or(false, |g| i64::try_from(g).is_ok())\n        && record.effective_gas_price.as_deref().map_or(true, |p| p.parse::<rust_decimal::Decimal>().is_ok())\n}","tryCatchPattern":"if let Err(e) = run_migration(&pool, records).await {\n    let msg = format!(\"{e:#}\");\n    if msg.contains(\"Failed to reconstruct migrated hash\") {\n        tracing::error!(\"hash UPDATE failed at DB level, check schema/constraints: {msg}\");\n    }\n    return Err(e); // transaction rolled back; state consistent\n}","preventionTips":["Keep target schema migrations in sync with the code version before running data migrations.","Validate numeric fields fit BIGINT and price strings parse as NUMERIC before migrating.","Normalize transaction hashes (lowercase hex) in evidence and DB.","Run data migrations in a maintenance window with no concurrent DDL."],"tags":["database","postgres","sqlx","migration","update-failed"],"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-14T00:17:10.932Z"}