{"record":{"id":"5ca8d9fe3e05e1e5","repo":"nautechsystems/nautilus_trader","slug":"failed-to-persist-execution-client-client-id-e","errorCode":null,"errorMessage":"Failed to persist execution client {client_id}: {e}","messagePattern":"Failed to persist execution client (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":1480,"sourceCode":"\n            if let Some(conflicting_client_id) = conflicting_client_id {\n                anyhow::bail!(\n                    \"Order {client_order_id} is already claimed by execution client \\\n                     {conflicting_client_id} and cannot be claimed by {client_id}\"\n                );\n            }\n\n            sqlx::query(\n                r#\"\n                INSERT INTO \"client\" (id)\n                VALUES ($1)\n                ON CONFLICT (id) DO NOTHING\n            \"#,\n            )\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            }","sourceCodeStart":1462,"sourceCodeEnd":1498,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L1462-L1498","documentation":"Within index_order_clients, the INSERT INTO \"client\" (id) ... ON CONFLICT DO NOTHING for the execution client failed; sqlx error wrapped in anyhow. This step upserts the client row before linking order events, so failure means the `client` table is missing/mismatched or the transaction connection broke. The transaction is aborted as a result.","triggerScenarios":"Calling index_order_clients when the `client` table does not exist or its `id` column type cannot accept the client_id string, or the DB connection fails during the INSERT.","commonSituations":"Partially initialized cache DB (order_event exists but client table missing); schema created by an older nautilus version; connection dropped mid-transaction.","solutions":["Read the chained sqlx error to identify missing table vs connection failure.","Run the full cache schema initialization so the `client` table exists.","Check DB connectivity and re-run index_order_clients; the transaction rolls back so it is safe to retry.","Verify the `client.id` column type/size fits your client_id strings."],"exampleFix":"// before\nqueries::postgres::index_order_clients(&mut tx, &client_order_id, &client_id).await?;\n// after\nsqlx::query(r#\"CREATE TABLE IF NOT EXISTS \"client\" (id VARCHAR PRIMARY KEY)\"#)\n    .execute(&mut *tx).await?;\nqueries::postgres::index_order_clients(&mut tx, &client_order_id, &client_id).await?;","handlingStrategy":"validation","validationCode":"let client_table = sqlx::query(r#\"SELECT 1 FROM \\\"client\\\" LIMIT 1\"#).fetch_optional(pool).await.is_ok();\nanyhow::ensure!(client_table, \"client table missing; run cache schema init first\");","typeGuard":null,"tryCatchPattern":"match queries::postgres::index_order_clients(&mut tx, &client_order_id, &client_id).await {\n    Err(e) if e.to_string().contains(\"Failed to persist execution client\") => {\n        anyhow::bail!(\"cache schema incomplete: {e:#}\");\n    }\n    other => other?,\n}","preventionTips":["Run the complete schema init (client, order_event, indexes) before indexing","Verify client.id column type fits your client_id strings","Check connectivity before long rebuilds","Retry safely — the transaction rolls back atomically"],"tags":["rust","database","sqlx","insert","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"}