{"record":{"id":"fa12042f977f4b63","repo":"quickwit-oss/tantivy","slug":"expected-type-string-which-is-always-sortable","errorCode":null,"errorMessage":"expected type string, which is always sortable","messagePattern":"expected type string, which is always sortable","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/aggregation/intermediate_agg_result.rs","lineNumber":954,"sourceCode":"                    key: key.into(),\n                    doc_count: entry.doc_count,\n                    sub_aggregation: entry\n                        .sub_aggregation\n                        .into_final_result_internal(sub_aggregation_req, limits)?,\n                })\n            })\n            .collect::<crate::Result<_>>()?;\n\n        let order = req.order.order;\n        match req.order.target {\n            OrderTarget::Key => {\n                buckets.sort_by(|left, right| {\n                    if req.order.order == Order::Asc {\n                        left.key.partial_cmp(&right.key)\n                    } else {\n                        right.key.partial_cmp(&left.key)\n                    }\n                    .expect(\"expected type string, which is always sortable\")\n                });\n            }\n            OrderTarget::Count => {\n                if req.order.order == Order::Desc {\n                    buckets.sort_unstable_by_key(|bucket| std::cmp::Reverse(bucket.doc_count()));\n                } else {\n                    buckets.sort_unstable_by_key(|bucket| bucket.doc_count());\n                }\n            }\n            OrderTarget::SubAggregation(name) => {\n                let (agg_name, agg_property) = get_agg_name_and_property(&name);\n                let mut buckets_with_val = buckets\n                    .into_iter()\n                    .map(|bucket| {\n                        let val = bucket\n                            .sub_aggregation\n                            .get_value_from_aggregation(agg_name, agg_property)?\n                            .unwrap_or(f64::MIN);","sourceCodeStart":936,"sourceCodeEnd":972,"githubUrl":"https://github.com/quickwit-oss/tantivy/blob/b5d8deb80c26924e6b007a5b1a7630f35ca64de4/src/aggregation/intermediate_agg_result.rs#L936-L972","documentation":"Fires when sorting final terms-agg buckets by key (OrderTarget::Key). Bucket keys are OwnedValue; the comparator uses partial_cmp and expects the key type to be string, which implements a total order, so the comparison never returns None. The panic indicates a bucket key of a non-string OwnedValue variant (e.g. numeric) reached a string-keyed terms aggregation, so the invariant 'string keys are always comparable' was violated.","triggerScenarios":"Thrown at src/aggregation/intermediate_agg_result.rs:954 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the terms aggregation request declares a string key type matching the indexed field","Confirm intermediate key conversion produced OwnedValue::Str for string-keyed buckets","If keys can be heterogeneous, replace the expect with an ordering that handles all OwnedValue variants"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b5d8deb80c26924e6b007a5b1a7630f35ca64de4","analyzedAt":"2026-09-05T13:20:51.521Z","contentChangedAt":"2026-09-05T13:20:51.521Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}