{"record":{"id":"1b81bc19d15e70e0","repo":"dbt-labs/dbt-core","slug":"group-by-with-non-string-key-name","errorCode":null,"errorMessage":"group_by with non-string key_name","messagePattern":"group_by with non-string key_name","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-agate/src/table.rs","lineNumber":1184,"sourceCode":"            //         the :code:`key` and the values are new :class:`.Table` instances\n            //         containing the grouped rows.\n            //     \"\"\"\n            // ```\n            \"group_by\" => {\n                let iter = ArgsIter::new(\"Table.group_by\", &[\"key\"], args);\n                let key = iter.next_arg::<&Value>()?;\n                let key_name = iter.next_kwarg::<Option<&Value>>(\"key_name\")?;\n                let key_type = iter.next_kwarg::<Option<&Value>>(\"key_type\")?;\n                iter.finish()?;\n\n                let key = match key.as_str() {\n                    Some(s) => s,\n                    None => unimplemented!(\"group_by with function key\"),\n                };\n                let key_name = match key_name {\n                    Some(v) => match v.as_str() {\n                        Some(s) => s,\n                        None => unimplemented!(\"group_by with non-string key_name\"),\n                    },\n                    None => \"group\",\n                };\n                let key_type = match key_type {\n                    Some(ty) => match ty.downcast_object_ref::<crate::DataType>() {\n                        Some(dt) => Some(dt.clone()),\n                        None => {\n                            // TODO: support DataType class instances\n                            unimplemented!(\"group_by with non-string key_type\")\n                        }\n                    },\n                    None => None,\n                };\n                let table_set = self\n                    .as_ref()\n                    .group_by_key(key, key_name, key_type)\n                    .map_err(|e| {\n                        Error::new(ErrorKind::InvalidOperation, format!(\"Table.group_by: {e}\"))","sourceCodeStart":1166,"sourceCodeEnd":1202,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-agate/src/table.rs#L1166-L1202","documentation":"dbt-agate's Rust Table object panics via unimplemented!() when group_by is called with a key_name argument that is not a string. The library only supports string column names as the group key name, and any other value type is treated as an unimplemented feature rather than a recoverable error.","triggerScenarios":"Calling table.group_by(...) and passing key_name as a non-string Value (e.g. an integer, a DataType object, or None-like object) instead of a string column name.","commonSituations":"Porting Python agate code where key_name could be any hashable; programmatic callers building kwargs dynamically and passing ints or column objects; typos passing the column itself instead of its name.","solutions":["Pass key_name as a string (e.g. use the column's name via str/column.name) instead of a non-string value","Omit key_name entirely; it defaults to \"group\"","If a dynamic name is needed, convert it to a string before the call"],"exampleFix":"// before\ntable.call_method(\"group_by\", kwargs!{\"key_name\" => Value::from(42)})\n// after\ntable.call_method(\"group_by\", kwargs!{\"key_name\" => Value::from(\"region\")})","handlingStrategy":"type-guard","validationCode":"let key_name_str = key_name.as_str().expect(\"key_name must be a string\");","typeGuard":"fn is_str(v: &Value) -> bool { v.as_str().is_some() }","tryCatchPattern":null,"preventionTips":["Always pass column names as strings to group_by key_name","Rely on the default \"group\" when no custom name is needed","Add unit tests covering group_by kwarg types"],"tags":["unimplemented","group-by","type-mismatch","rust"],"backgroundTag":"unsupported-operation","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}