{"record":{"id":"553c65375eb8aa3c","repo":"nautechsystems/nautilus_trader","slug":"failed-to-load-position-ids-e","errorCode":null,"errorMessage":"Failed to load position ids: {e}","messagePattern":"Failed to load position ids: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":991,"sourceCode":"    /// # Errors\n    ///\n    /// Returns an error if loading position IDs or replaying any position fails.\n    pub async fn load_positions(pool: &PgPool) -> anyhow::Result<Vec<Position>> {\n        let position_ids: Vec<PositionId> = sqlx::query(\n            r#\"\n            SELECT DISTINCT position_id\n            FROM \"position_event\"\n            ORDER BY position_id ASC\n        \"#,\n        )\n        .fetch_all(pool)\n        .await\n        .map(|rows| {\n            rows.into_iter()\n                .map(|row| PositionId::from(row.get::<&str, _>(0)))\n                .collect()\n        })\n        .map_err(|e| anyhow::anyhow!(\"Failed to load position ids: {e}\"))?;\n\n        let mut positions = Vec::new();\n\n        for id in position_ids {\n            match Self::load_position(pool, &id).await {\n                Ok(Some(position)) => positions.push(position),\n                Ok(None) => log::error!(\"Position not found: {id}\"),\n                Err(e) => log::error!(\"Failed to load position {id}: {e}\"),\n            }\n        }\n\n        Ok(positions)\n    }\n\n    async fn insert_position_event(\n        transaction: &mut Transaction<'_, Postgres>,\n        event: &OrderFilled,\n    ) -> anyhow::Result<()> {","sourceCodeStart":973,"sourceCodeEnd":1009,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L973-L1009","documentation":"load_positions first queries the distinct position_ids from the position events table; if that SELECT fails the sqlx error is wrapped in this message. No positions are returned because the id enumeration itself failed.","triggerScenarios":"Calling DatabaseQuery::load_positions(pool, venue) and the id query errors: missing table, connection failure, or SQL error wrapped via anyhow.","commonSituations":"Database not migrated; wrong venue filter against an empty/uninitialized schema; connectivity loss at query time; insufficient SELECT privileges.","solutions":["Inspect the wrapped sqlx error for the root cause.","Run the nautilus SQL migrations so the position tables exist.","Confirm the venue/instance filters match data actually written to this database.","Verify connectivity and privileges, then retry if the failure was transient."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"sqlx::query(\"SELECT 1 FROM position_event LIMIT 1\").fetch_optional(&pool).await?;","typeGuard":null,"tryCatchPattern":"match load_positions(&pool, &venue).await {\n    Err(e) if is_transient_db_error(&e) => retry_with_backoff(3),\n    other => other,\n}","preventionTips":["Run migrations before first use of the SQL cache.","Confirm venue/instance filters match the data in this database.","Grant the DB user the required SELECT privileges."],"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"}