{"record":{"id":"fd3a553835d38b50","repo":"nautechsystems/nautilus_trader","slug":"failed-to-serialize-exec-algorithm-params-e","errorCode":null,"errorMessage":"Failed to serialize exec algorithm params: {e}","messagePattern":"Failed to serialize exec algorithm params: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":660,"sourceCode":"        // TODO remove this when client initialization is implemented\n        if let Some(client_id) = client_id {\n            sqlx::query(\n                r#\"\n                INSERT INTO \"client\" (id) VALUES ($1) ON CONFLICT (id) DO NOTHING\n            \"#,\n            )\n            .bind(client_id.to_string())\n            .execute(&mut *transaction)\n            .await\n            .map(|_| ())\n            .map_err(|e| anyhow::anyhow!(\"Failed to insert into client table: {e}\"))?;\n        }\n\n        let exec_algorithm_params = order_event\n            .exec_algorithm_params()\n            .map(serde_json::to_value)\n            .transpose()\n            .map_err(|e| anyhow::anyhow!(\"Failed to serialize exec algorithm params: {e}\"))?;\n        let info = order_event\n            .info()\n            .map(serde_json::to_value)\n            .transpose()\n            .map_err(|e| anyhow::anyhow!(\"Failed to serialize order event info: {e}\"))?;\n\n        sqlx::query(r#\"\n            INSERT INTO \"order_event\" (\n                id, kind, client_order_id, order_type, order_side, trader_id, client_id, reason, strategy_id, instrument_id, trade_id, currency, quantity, time_in_force, liquidity_side,\n                post_only, reduce_only, quote_quantity, reconciliation, price, last_px, last_qty, trigger_price, trigger_type, limit_offset, trailing_offset,\n                trailing_offset_type, expire_time, display_qty, emulation_trigger, trigger_instrument_id, contingency_type,\n                order_list_id, linked_order_ids, parent_order_id,\n                exec_algorithm_id, exec_spawn_id, venue_order_id, account_id, position_id, commission, ts_event, ts_init, activation_price, exec_algorithm_params, tags,\n                released_price, protection_price, due_post_only, correction_id, is_reopened, info, causation_id, created_at, updated_at\n            ) VALUES (\n                $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20,\n                $21, $22, $23, $24, $25, $26::trailing_offset_type, $27, $28, $29, $30, $31, $32, $33, $34,\n                $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46,","sourceCodeStart":642,"sourceCodeEnd":678,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L642-L678","documentation":"Raised by `add_order_event` when `order_event.exec_algorithm_params()` is `Some` but the value cannot be serialized to JSON via `serde_json::to_value`. This is a local serialization failure before any SQL executes, so the transaction is untouched. It indicates the params type contains data serde_json cannot represent (e.g., non-string map keys) or a custom serializer bug.","triggerScenarios":"Calling `add_order_event` on an `OrderEventAny` whose exec algorithm params implement serialization in a way `serde_json` rejects — typically maps with non-string keys, or a Serialize impl returning an error.","commonSituations":"Custom exec algorithm params using `HashMap<u64, _>` or similar non-string keys; a broken hand-written `Serialize` implementation; version changes in serde_json dropping support for a previously-serialized shape.","solutions":["Inspect `{e}` (a `serde_json::Error`) for which value failed serialization.","Change exec algorithm params to use string keys (e.g., `HashMap<String, T>`) so they are JSON-compatible.","Fix or regenerate the `Serialize` implementation for the params type.","Pre-test serialization with `serde_json::to_value(&params)` before persisting events."],"exampleFix":"// before\nparams: HashMap<u64, OrderFilled>,\n// after\nparams: HashMap<String, OrderFilled>, // serde_json-compatible keys","handlingStrategy":"validation","validationCode":"// Validate params are JSON-serializable before calling add_order_event\nif let Some(params) = event.exec_algorithm_params() {\n    serde_json::to_value(params)\n        .map_err(|e| anyhow::anyhow!(\"exec params not JSON-serializable: {e}\"))?;\n}","typeGuard":"fn is_json_serializable<T: serde::Serialize>(value: &T) -> bool {\n    serde_json::to_value(value).is_ok()\n}","tryCatchPattern":"// Prefer validation; if catching:\nmatch serde_json::to_value(params) {\n    Ok(v) => { /* proceed */ }\n    Err(e) => log::error!(\"params serialization failed: {e}\"),\n}","preventionTips":["Use string-keyed maps in exec algorithm params.","Add a unit test that round-trips params through serde_json.","Keep serde and serde_json versions aligned across the workspace."],"tags":["serialization","serde","json","rust"],"backgroundTag":"json-marshal-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"}