{"record":{"id":"fc1197acb1e3abe2","repo":"nautechsystems/nautilus_trader","slug":"invalid-ordertype","errorCode":null,"errorMessage":"Invalid `OrderType`","messagePattern":"Invalid `OrderType`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/infrastructure/src/sql/models/orders.rs","lineNumber":1058,"sourceCode":"        let venue_order_id = row\n            .try_get::<Option<&str>, _>(\"venue_order_id\")\n            .ok()\n            .and_then(|x| x.map(VenueOrderId::from));\n        let position_id = row\n            .try_get::<Option<&str>, _>(\"position_id\")\n            .ok()\n            .and_then(|x| x.map(PositionId::from));\n        let account_id = row\n            .try_get::<Option<&str>, _>(\"account_id\")\n            .ok()\n            .and_then(|x| x.map(AccountId::from));\n        let last_trade_id = row\n            .try_get::<Option<&str>, _>(\"last_trade_id\")\n            .ok()\n            .and_then(|x| x.map(TradeId::from));\n        let order_type = row\n            .try_get::<&str, _>(\"order_type\")\n            .map(|x| OrderType::from_str(x).expect(\"Invalid `OrderType`\"))?;\n        let order_side = row\n            .try_get::<&str, _>(\"order_side\")\n            .map(|x| OrderSide::from_str(x).expect(\"Invalid `OrderSide`\"))?;\n        let quantity = row.try_get::<&str, _>(\"quantity\").map(Quantity::from)?;\n        let price = row\n            .try_get::<Option<&str>, _>(\"price\")\n            .ok()\n            .and_then(|x| x.map(Price::from));\n        let activation_price = row\n            .try_get::<Option<&str>, _>(\"activation_price\")\n            .ok()\n            .and_then(|x| x.map(Price::from));\n        let trigger_price = row\n            .try_get::<Option<&str>, _>(\"trigger_price\")\n            .ok()\n            .and_then(|x| x.map(Price::from));\n        let trigger_type = row\n            .try_get::<Option<&str>, _>(\"trigger_type\")","sourceCodeStart":1040,"sourceCodeEnd":1076,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/models/orders.rs#L1040-L1076","documentation":"When hydrating an order from a SQL row, the `order_type` column string is parsed with `OrderType::from_str` and the result is unwrapped with expect(). The library panics because an order type stored in the database does not map to any known `OrderType` variant — Nautilus treats the DB row as trusted and considers a corrupt enum value unrecoverable for that row.","triggerScenarios":"Calling `OrderModel::from_row` (during query deserialization of orders) where the `order_type` column contains a string not in the OrderType enum (wrong case, truncated value, vendor-specific type like 'STOP_LOSS_LIMIT' not modeled, or NULL-handling surprises).","commonSituations":"Schema written by a different nautilus version or another trading system sharing the table; manual SQL inserts/updates; adapters writing adapter-specific order type strings instead of the canonical nautilus values.","solutions":["Query the offending row (`SELECT id, order_type FROM orders WHERE order_type NOT IN (...)`) and fix or delete it","Check the writer path — ensure orders are inserted using OrderType's canonical serialization (Display/AsRefStr), not adapter strings","Update nautilus or the adapter so the enum variant exists before reading rows written with newer values","Replace expect with proper error propagation (`?` with a mapped error) if you control a fork of this model"],"exampleFix":"// before\nOrderType::from_str(x).expect(\"Invalid `OrderType`\")\n// after\nOrderType::from_str(x).map_err(|e| ModelError::Parse(format!(\"invalid order_type '{x}': {e}\")))?","handlingStrategy":"type-guard","validationCode":"const VALID_ORDER_TYPES: &[&str] = &[\"MARKET\",\"LIMIT\",\"STOP_MARKET\",\"STOP_LIMIT\",\"MARKET_TO_LIMIT\",\"MARKET_IF_TOUCHED\",\"LIMIT_IF_TOUCHED\",\"TRAILING_STOP_MARKET\",\"TRAILING_STOP_LIMIT\"];\nassert!(VALID_ORDER_TYPES.contains(&order_type_str));","typeGuard":"fn is_known_order_type(s: &str) -> bool {\n    OrderType::from_str(s).is_ok()\n}","tryCatchPattern":"let order_type = OrderType::from_str(x)\n    .map_err(|e| ModelError::Parse(format!(\"row {}: invalid order_type '{x}': {e}\", row_id)))?;","preventionTips":["Only write enum values via nautilus canonical serialization, never raw adapter strings","Add a CHECK constraint on order_type in the schema","Validate enum strings at insertion boundaries","Re-migrate data after upgrading nautilus versions"],"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-14T00:17:10.932Z"}