{"record":{"id":"50acd0dbd6259689","repo":"nautechsystems/nautilus_trader","slug":"no-persisted-order-events-found-for-client-order","errorCode":null,"errorMessage":"No persisted order events found for {client_order_id}","messagePattern":"No persisted order events found for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":1497,"sourceCode":"            .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(\n        pool: &PgPool,\n        client_order_id: ClientOrderId,\n        position_id: PositionId,","sourceCodeStart":1479,"sourceCodeEnd":1515,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L1479-L1515","documentation":"Thrown by `index_order_clients` when the INSERT into the order-client index affects zero rows, meaning no persisted order events exist for the given client_order_id. The index can only be written for orders already persisted; otherwise it bails.","triggerScenarios":"Calling `index_order_clients` with a client_order_id that was never persisted to the order events tables (e.g. indexing before the order is written, or the order_id is wrong/typos in venue vs client order id).","commonSituations":"Calling the indexing step out of order (before persisting order events); using a stale client_order_id after order modification; pointing at a database that does not contain the order (different environment).","solutions":["Persist the order's events before calling `index_order_clients` — verify the order row exists with a SELECT on client_order_id.","Check the client_order_id for correctness (truncation, venue-prefixed vs client-prefixed formats).","Confirm you are connected to the database the order was written to."],"exampleFix":"// before: indexing first\nqueries.index_order_clients(&pool, &client_order_id, &client_id).await?;\nqueries.add_order(&pool, &order).await?;\n\n// after: persist order events first\nqueries.add_order(&pool, &order).await?;\nqueries.index_order_clients(&pool, &client_order_id, &client_id).await?;","handlingStrategy":"validation","validationCode":"let order_exists = sqlx::query_scalar::<_, bool>(\n    \"SELECT EXISTS(SELECT 1 FROM orders WHERE client_order_id = $1)\",\n)\n.bind(client_order_id.to_string())\n.fetch_one(&pool).await?;\nif !order_exists {\n    // persist order events before indexing\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = queries.index_order_clients(&pool, &client_order_id, &client_id).await {\n    if e.to_string().contains(\"No persisted order events\") {\n        // persist the order first, then retry the index call\n    } else { return Err(e); }\n}","preventionTips":["Always persist order events before indexing the order-client mapping.","Validate client_order_id formats (never truncate or mix venue/client prefixes).","Confirm the target database actually contains the order before indexing."],"tags":["database","record-not-found","ordering","rust"],"backgroundTag":"entity-not-found","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"}