{"record":{"id":"094655a8126e0eab","repo":"nautechsystems/nautilus_trader","slug":"failed-to-load-order-ids-e","errorCode":null,"errorMessage":"Failed to load order ids: {e}","messagePattern":"Failed to load order ids: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":828,"sourceCode":"    ///\n    /// # Errors\n    ///\n    /// Returns an error if loading events or SQL operations fail.\n    pub async fn load_orders(pool: &PgPool) -> anyhow::Result<Vec<OrderAny>> {\n        let mut orders: Vec<OrderAny> = Vec::new();\n        let client_order_ids: Vec<ClientOrderId> = sqlx::query(\n            r#\"\n            SELECT DISTINCT client_order_id FROM \"order_event\"\n        \"#,\n        )\n        .fetch_all(pool)\n        .await\n        .map(|rows| {\n            rows.into_iter()\n                .map(|row| ClientOrderId::from(row.get::<&str, _>(0)))\n                .collect()\n        })\n        .map_err(|e| anyhow::anyhow!(\"Failed to load order ids: {e}\"))?;\n        for id in client_order_ids {\n            let order = Self::load_order(pool, &id).await?;\n            if let Some(order) = order {\n                orders.push(order);\n            }\n        }\n        Ok(orders)\n    }\n\n    /// Replaces the fill event log for a `position_id` via the provided `pool`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the fill is invalid or if the SQL operations fail.\n    pub async fn add_position(\n        pool: &PgPool,\n        position_id: PositionId,\n        event: &OrderFilled,","sourceCodeStart":810,"sourceCodeEnd":846,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L810-L846","documentation":"load_orders first queries the distinct client_order_ids from the order events table; if that SELECT fails the sqlx error is wrapped in this message. No orders are loaded when this fires since the id list could not be built.","triggerScenarios":"Calling DatabaseQuery::load_orders(pool) and the id-enumeration query fails: missing table, connection failure, or SQL error surfaced through sqlx and wrapped by anyhow.","commonSituations":"Fresh database without migrations applied; database unreachable at startup; insufficient SELECT privileges on the order tables.","solutions":["Inspect the wrapped sqlx error for the root cause (missing relation, connection refused, etc.).","Apply the nautilus SQL migrations to create the order tables.","Verify DB credentials and that the user can SELECT from the order event table.","Check pool connectivity settings (max lifetime, timeouts) if failures are intermittent."],"exampleFix":"// before\nlet orders = DatabaseQuery::load_orders(&pool).await?;\n// after\nlet orders = DatabaseQuery::load_orders(&pool).await\n    .context(\"ensure migrations applied and DB reachable\")?;","handlingStrategy":"retry","validationCode":"sqlx::query(\"SELECT 1 FROM order_event LIMIT 1\").fetch_optional(&pool).await?;","typeGuard":null,"tryCatchPattern":"match load_orders(&pool).await {\n    Err(e) if is_transient_db_error(&e) => retry_with_backoff(3),\n    other => other,\n}","preventionTips":["Run migrations as part of deployment, not on first query.","Grant the DB user SELECT on all nautilus cache tables.","Keep the pool's connection settings within network idle limits."],"tags":["rust","database","sqlx","postgres"],"backgroundTag":"database-query-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"}