{"record":{"id":"35817d90d813731e","repo":"databendlabs/databend","slug":"fail-to-serialize-scalar","errorCode":null,"errorMessage":"fail to serialize Scalar","messagePattern":"fail to serialize Scalar","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/service/src/servers/http/v1/query/http_query.rs","lineNumber":266,"sourceCode":"    #[serde(default)]\n    #[serde(skip_serializing_if = \"is_default\")]\n    pub last_query_ids: Vec<String>,\n}\n\nimpl HttpSessionStateInternal {\n    fn new(\n        variables: &HashMap<String, Scalar>,\n        last_query_result_cache_key: String,\n        has_temp_table: bool,\n        last_node_id: Option<String>,\n        last_query_ids: Vec<String>,\n    ) -> Self {\n        let variables = variables\n            .iter()\n            .map(|(k, v)| {\n                (\n                    k.clone(),\n                    serde_json::to_string(&v).expect(\"fail to serialize Scalar\"),\n                )\n            })\n            .collect();\n        Self {\n            variables,\n            last_query_result_cache_key,\n            has_temp_table,\n            last_node_id,\n            last_query_ids,\n        }\n    }\n\n    pub fn get_variables(&self) -> Result<HashMap<String, Scalar>> {\n        let mut vars = HashMap::with_capacity(self.variables.len());\n        for (k, v) in self.variables.iter() {\n            match serde_json::from_str::<Scalar>(v) {\n                Ok(s) => {\n                    vars.insert(k.to_string(), s);","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/service/src/servers/http/v1/query/http_query.rs#L248-L284","documentation":"When constructing the HTTP query request state, each session variable (`Scalar`) is serialized to a JSON string with `serde_json::to_string(&v).expect(\"fail to serialize Scalar\")`. `Scalar`'s JSON serialization is expected to be infallible; a `Err` means the scalar value (e.g., a struct/variant payload) could not be represented as JSON — typically a serde serializer error from an unsupported value or a serialization bug in `Scalar`'s `Serialize` impl. The panic aborts HTTP query request creation.","triggerScenarios":"`new(variables, ...)` on the HTTP query request struct receiving a session variable whose `Scalar` serialization fails — e.g., a newly introduced Scalar variant without a JSON `Serialize` implementation, or a nested value exceeding serde limits.","commonSituations":"Setting exotic session variables (large structs, new data types) through `SET` before running a query over the HTTP API; development builds where a new Scalar type was added without updating serde support.","solutions":["Identify which session variable fails (iterate `variables` and test `serde_json::to_string` per value); unset or change it before issuing the HTTP query.","If a custom/new `Scalar` variant is involved, implement or fix its `Serialize` impl so JSON serialization always succeeds.","Upgrade Databend if this occurs with standard variables — it indicates a fixed serialization bug.","Replace the expect with `map_err(...)` into a server error so the HTTP API returns 4xx/5xx instead of panicking."],"exampleFix":"// before\nserde_json::to_string(&v).expect(\"fail to serialize Scalar\"),\n\n// after\nserde_json::to_string(&v).map_err(|e| {\n    ErrorCode::Internal(format!(\"fail to serialize Scalar '{}': {}\", k, e))\n})?,","handlingStrategy":"try-catch","validationCode":"// Before issuing the HTTP query, sanity-check session variables are JSON-serializable\nfor (k, v) in &variables {\n    serde_json::to_string(v).unwrap_or_else(|e| panic!(\"session var '{}' not serializable: {}\", k, e));\n}","typeGuard":null,"tryCatchPattern":"// Library-side hardening\nserde_json::to_string(&v).map_err(|e| {\n    ErrorCode::Internal(format!(\"fail to serialize Scalar '{}': {}\", k, e))\n})?","preventionTips":["Avoid setting exotic/experimental session variables before HTTP queries.","When adding a new Scalar variant, always implement and test its serde Serialize impl.","Add round-trip serde tests for Scalar in CI."],"tags":["json","serialization","panic","http-api","rust"],"backgroundTag":"json-serialization-failed","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}