{"record":{"id":"4dfb1d3375d16cef","repo":"nautechsystems/nautilus_trader","slug":"failed-to-index-order-client-origin-e","errorCode":null,"errorMessage":"Failed to index order client origin: {e}","messagePattern":"Failed to index order client origin: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":1494,"sourceCode":"            )\n            .bind(client_id.to_string())\n            .execute(&mut *transaction)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to persist execution client {client_id}: {e}\"))?;\n\n            let result = sqlx::query(\n                r#\"\n                UPDATE \"order_event\"\n                SET client_id = $2\n                WHERE client_order_id = $1\n                  AND (client_id IS NULL OR client_id = $2)\n            \"#,\n            )\n            .bind(client_order_id.to_string())\n            .bind(client_id.to_string())\n            .execute(&mut *transaction)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to index order client origin: {e}\"))?;\n\n            if result.rows_affected() == 0 {\n                anyhow::bail!(\"No persisted order events found for {client_order_id}\");\n            }\n        }\n\n        transaction\n            .commit()\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to commit order client origins: {e}\"))\n    }\n\n    /// Inserts or updates an order ID to position ID index entry via the provided `pool`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the SQL INSERT or UPDATE operation fails.\n    pub async fn index_order_position(","sourceCodeStart":1476,"sourceCodeEnd":1512,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L1476-L1512","documentation":"index_order_clients wraps the failure of the final UPDATE \"order_event\" SET client_id = $2 WHERE client_order_id = $1 as 'Failed to index order client origin'. This is the core write of the client-id mapping; any sqlx error here (missing column, connection loss, lock timeout) aborts the transaction. Distinct from the rows_affected==0 bail which is the 'No persisted order events' error.","triggerScenarios":"Calling index_order_clients when the UPDATE fails: order_event table/columns mismatch current query, DB connection drops during execute, or the row is locked by another writer.","commonSituations":"Schema drift after upgrade (order_event columns renamed); long-running rebuild colliding with concurrent writers; DB restart mid-transaction.","solutions":["Inspect the chained sqlx error for the exact DB complaint.","Re-run schema initialization/migrations so `order_event` has client_order_id and client_id columns as expected.","Retry the operation after transient errors — the transaction rollback leaves state consistent.","Avoid concurrent writers on the same order rows or use appropriate isolation."],"exampleFix":"// before\nqueries::postgres::index_order_clients(&mut tx, &client_order_id, &client_id).await?;\n// after\nlet result = queries::postgres::index_order_clients(&mut tx, &client_order_id, &client_id).await;\nif let Err(e) = &result {\n    tracing::error!(source = ?std::error::Error::source(e), \"order client indexing failed\");\n}\nresult?;","handlingStrategy":"try-catch","validationCode":"let cols = sqlx::query(r#\"SELECT column_name FROM information_schema.columns WHERE table_name = 'order_event'\"#)\n    .fetch_all(pool).await?;\nlet names: Vec<_> = cols.into_iter().map(|r| r.get::<String, _>(0)).collect();\nanyhow::ensure!(names.contains(&\"client_id\".to_string()), \"order_event.client_id column missing\");","typeGuard":null,"tryCatchPattern":"match queries::postgres::index_order_clients(&mut tx, &client_order_id, &client_id).await {\n    Ok(()) => (),\n    Err(e) => {\n        tracing::error!(source = ?std::error::Error::source(&e), \"order client origin update failed\");\n        return Err(e); // tx rolled back; safe to retry later\n    }\n}","preventionTips":["Keep schema migrations in sync with nautilus version","Inspect the sqlx source error to distinguish schema vs connectivity causes","Avoid concurrent updates to the same order_event rows","Retry whole transactions, not individual statements"],"tags":["rust","database","sqlx","update","anyhow"],"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-14T05:17:10.506Z"}