{"record":{"id":"537249a811c819d3","repo":"nautechsystems/nautilus_trader","slug":"failed-to-serialize-bybitsmptype","errorCode":null,"errorMessage":"Failed to serialize BybitSmpType","messagePattern":"Failed to serialize BybitSmpType","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/adapters/bybit/src/http/models.rs","lineNumber":1129,"sourceCode":"    pub fn reduce_only(&self) -> bool {\n        self.reduce_only\n    }\n\n    #[getter]\n    #[must_use]\n    pub fn close_on_trigger(&self) -> bool {\n        self.close_on_trigger\n    }\n\n    #[getter]\n    #[must_use]\n    #[expect(\n        clippy::missing_panics_doc,\n        reason = \"serialization of a simple enum cannot fail\"\n    )]\n    pub fn smp_type(&self) -> String {\n        serde_json::to_string(&self.smp_type)\n            .expect(\"Failed to serialize BybitSmpType\")\n            .trim_matches('\"')\n            .to_string()\n    }\n\n    #[getter]\n    #[must_use]\n    pub fn smp_group(&self) -> i32 {\n        self.smp_group\n    }\n\n    #[getter]\n    #[must_use]\n    pub fn smp_order_id(&self) -> &str {\n        self.smp_order_id.as_str()\n    }\n\n    #[getter]\n    #[must_use]","sourceCodeStart":1111,"sourceCodeEnd":1147,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bybit/src/http/models.rs#L1111-L1147","documentation":"The PyO3 getter `BybitOrder.smp_type()` serializes the `BybitSmpType` enum to JSON with `serde_json::to_string(...).expect(...)`, then strips the surrounding quotes. Serialization of a field-less enum cannot fail under normal operation (the code even carries a `clippy::missing_panics_doc` exemption asserting this), so the panic would indicate a corrupted internal state or a non-serializable enum variant introduced by a change.","triggerScenarios":"Practically unreachable; would require `BybitSmpType` to gain a variant/representation that serde cannot serialize (e.g. a non-string-serializable variant) or corrupted memory. Could surface after a hand-edit of the enum that breaks its serde derive.","commonSituations":"Reproducing after modifying `BybitSmpType` (adding variants without proper serde attributes); calling the Python getter `order.smp_type` on a deserialized order object.","solutions":["Verify `BybitSmpType` still derives `Serialize` and all variants are plain unit variants","Rebuild the extension module after any change to the enum","If a variant is not string-serializable, return the debug/name string instead of JSON round-tripping","Report upstream if the panic occurs on an unmodified build"],"exampleFix":"// before\nserde_json::to_string(&self.smp_type).expect(\"Failed to serialize BybitSmpType\").trim_matches('\"').to_string()\n// after\nself.smp_type.to_string() // or map_err into a PythonError and return Result<...>","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Rust: ensure the enum is a unit-only enum before JSON round-tripping\nfn is_unit_variant(v: &BybitSmpType) -> bool { matches!(v, BybitSmpType::None | BybitSmpType::Cancel | BybitSmpType::ReduceOnly) }","tryCatchPattern":"// Python side: wrap getter access defensively\ntry:\n    smp = order.smp_type\nexcept Exception as e:\n    smp = None  # and report the deserialization issue","preventionTips":["Do not hand-edit serde derives on BybitSmpType; change via the generator/source","Prefer Display/to_string over JSON round-trip for unit enums in PyO3 getters","Add a unit test covering smp_type() for every enum variant"],"tags":["serialization","pyo3","enum","smp"],"backgroundTag":"json-serialization-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"}