{"record":{"id":"acdf241deb2372c7","repo":"nautechsystems/nautilus_trader","slug":"invalid-orderstatus","errorCode":null,"errorMessage":"Invalid `OrderStatus`","messagePattern":"Invalid `OrderStatus`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/infrastructure/src/sql/models/orders.rs","lineNumber":1113,"sourceCode":"        let expire_time = row\n            .try_get::<Option<&str>, _>(\"expire_time\")\n            .ok()\n            .and_then(|x| x.map(UnixNanos::from));\n        let filled_qty = row.try_get::<&str, _>(\"filled_qty\").map(Quantity::from)?;\n        let liquidity_side = row\n            .try_get::<Option<&str>, _>(\"liquidity_side\")\n            .ok()\n            .and_then(|x| x.map(|x| LiquiditySide::from_str(x).expect(\"Invalid `LiquiditySide`\")));\n        let avg_px = row.try_get::<Option<Decimal>, _>(\"avg_px\").ok().flatten();\n        let slippage = row.try_get::<Option<Decimal>, _>(\"slippage\").ok().flatten();\n        let commissions = row\n            .try_get::<Option<Vec<String>>, _>(\"commissions\")?\n            .map_or_else(Vec::new, |c| {\n                c.into_iter().map(|s| Money::from(&s)).collect()\n            });\n        let status = row\n            .try_get::<&str, _>(\"status\")\n            .map(|x| OrderStatus::from_str(x).expect(\"Invalid `OrderStatus`\"))?;\n        let is_post_only = row.try_get::<bool, _>(\"is_post_only\")?;\n        let is_reduce_only = row.try_get::<bool, _>(\"is_reduce_only\")?;\n        let is_quote_quantity = row.try_get::<bool, _>(\"is_quote_quantity\")?;\n        let display_qty = row\n            .try_get::<Option<&str>, _>(\"display_qty\")\n            .ok()\n            .and_then(|x| x.map(Quantity::from));\n        let emulation_trigger = row\n            .try_get::<Option<&str>, _>(\"emulation_trigger\")\n            .ok()\n            .and_then(parse_trigger_type);\n        let trigger_instrument_id = row\n            .try_get::<Option<&str>, _>(\"trigger_instrument_id\")\n            .ok()\n            .and_then(|x| x.map(InstrumentId::from));\n        let contingency_type = row\n            .try_get::<Option<&str>, _>(\"contingency_type\")\n            .ok()","sourceCodeStart":1095,"sourceCodeEnd":1131,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/models/orders.rs#L1095-L1131","documentation":"The `status` column string is parsed with `OrderStatus::from_str` and unwrapped with expect() during order row hydration. The panic means the stored status (expected e.g. 'INITIALIZED','SUBMITTED','FILLED',...) is not a valid OrderStatus variant, making the row undeserializable.","triggerScenarios":"Calling `OrderModel::from_row` where `status` holds an unknown value: adapter-only states like 'PARTIALLY_FILLED_CANCELLED', case/whitespace mismatches, or statuses written by a newer/older nautilus version.","commonSituations":"Schema shared across nautilus versions where the OrderStatus enum changed; external order-management systems writing their own statuses; manual data fixes.","solutions":["Find bad rows: `SELECT id, status FROM orders WHERE status NOT IN (<valid list>)` and correct them","Ensure the writer serializes OrderStatus via its canonical string conversion","Align data with the nautilus version in use — migrate rows after upgrading the library","Propagate a parse error instead of expect for rows from untrusted sources"],"exampleFix":"// before\nOrderStatus::from_str(x).expect(\"Invalid `OrderStatus`\")\n// after\nOrderStatus::from_str(x).map_err(|e| ModelError::Parse(format!(\"invalid status '{x}': {e}\")))?","handlingStrategy":"type-guard","validationCode":"fn is_known_order_status(s: &str) -> bool {\n    OrderStatus::from_str(s).is_ok()\n}\n// use before reading: assert!(is_known_order_status(status_str));","typeGuard":"fn is_known_order_status(s: &str) -> bool {\n    OrderStatus::from_str(s).is_ok()\n}","tryCatchPattern":"let status = OrderStatus::from_str(x)\n    .map_err(|e| ModelError::Parse(format!(\"row {}: invalid status '{x}': {e}\", row_id)))?;","preventionTips":["Map adapter-specific states to canonical OrderStatus before persisting","Add a CHECK constraint on status","Round-trip test all OrderStatus variants through the SQL model","Run a status audit query after nautilus upgrades"],"tags":["rust","sql","postgres","enum","panic"],"backgroundTag":"invalid-enum-value","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"}