{"record":{"id":"3f1ef5c4971d7b7b","repo":"nautechsystems/nautilus_trader","slug":"delete-position-not-implemented-for-postgresql-cac","errorCode":null,"errorMessage":"delete_position not implemented for PostgreSQL cache adapter: {position_id}","messagePattern":"delete_position not implemented for PostgreSQL cache adapter: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/cache.rs","lineNumber":897,"sourceCode":"        todo!()\n    }\n\n    fn load_strategy(&self, strategy_id: &StrategyId) -> anyhow::Result<AHashMap<String, Bytes>> {\n        anyhow::bail!(\"load_strategy not implemented for PostgreSQL cache adapter: {strategy_id}\")\n    }\n\n    fn delete_strategy(&self, _strategy_id: &StrategyId) -> anyhow::Result<()> {\n        todo!()\n    }\n\n    fn delete_order(&self, client_order_id: &ClientOrderId) -> anyhow::Result<()> {\n        anyhow::bail!(\n            \"delete_order not implemented for PostgreSQL cache adapter: {client_order_id}\"\n        )\n    }\n\n    fn delete_position(&self, position_id: &PositionId) -> anyhow::Result<()> {\n        anyhow::bail!(\"delete_position not implemented for PostgreSQL cache adapter: {position_id}\")\n    }\n\n    fn delete_account_event(&self, account_id: &AccountId, event_id: &str) -> anyhow::Result<()> {\n        anyhow::bail!(\n            \"delete_account_event not implemented for PostgreSQL cache adapter: {account_id}, {event_id}\"\n        )\n    }\n\n    fn add(&self, key: String, value: Bytes) -> anyhow::Result<()> {\n        let query = DatabaseQuery::Add(key, value.into());\n        self.tx\n            .send(query)\n            .map_err(|e| anyhow::anyhow!(\"Failed to send query to database message handler: {e}\"))\n    }\n\n    fn add_currency(&self, currency: &Currency) -> anyhow::Result<()> {\n        let query = DatabaseQuery::AddCurrency(*currency);\n        self.tx.send(query).map_err(|e| {","sourceCodeStart":879,"sourceCodeEnd":915,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/cache.rs#L879-L915","documentation":"Sentinel error in the PostgreSQL cache adapter's delete_position: position deletion is not implemented for the PostgreSQL cache backend, so the operation always fails and reports the position ID involved.","triggerScenarios":"Calling cache.delete_position for a PositionId with the PostgreSQL cache adapter — e.g. purging closed positions or cleanup tooling.","commonSituations":"Maintenance jobs ported from the Redis adapter; freeing storage of historical closed positions; test teardown on a shared Postgres cache.","solutions":["Avoid deleting positions on the SQL adapter; query/filter closed positions instead of removing them","Use the Redis adapter where position deletion is needed","Implement delete_position in sql/cache.rs with the corresponding SQL DELETE"],"exampleFix":"// before\ncache_db.delete_position(&position_id)?; // bails on Postgres\n// after\nlet result = cache_db.delete_position(&position_id);\nif let Err(e) = result { log::warn!(\"delete_position unsupported: {e}\"); }","handlingStrategy":"try-catch","validationCode":"if is_postgres_cache(&cache_db) { /* deletion unsupported — skip */ }","typeGuard":"fn is_postgres_cache(db: &dyn CacheDatabase) -> bool { db.as_any().downcast_ref::<PostgresCache>().is_some() }","tryCatchPattern":"if let Err(e) = cache_db.delete_position(&position_id) {\n    if e.to_string().contains(\"not implemented\") {\n        log::debug!(\"position retained in SQL cache (delete unsupported)\");\n    } else { return Err(e); }\n}","preventionTips":["Archive/filter closed positions instead of deleting them","Keep maintenance tooling adapter-aware","Add capability checks shared by all delete operations"],"tags":["postgresql","cache","not-implemented","position","delete"],"backgroundTag":"method-not-implemented","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"}