dbt-labs/dbt-core · error
group_by with non-string key_name
Error message
group_by with non-string key_name
What it means
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.
Source
Thrown at crates/dbt-agate/src/table.rs:1184
// the :code:`key` and the values are new :class:`.Table` instances
// containing the grouped rows.
// """
// ```
"group_by" => {
let iter = ArgsIter::new("Table.group_by", &["key"], args);
let key = iter.next_arg::<&Value>()?;
let key_name = iter.next_kwarg::<Option<&Value>>("key_name")?;
let key_type = iter.next_kwarg::<Option<&Value>>("key_type")?;
iter.finish()?;
let key = match key.as_str() {
Some(s) => s,
None => unimplemented!("group_by with function key"),
};
let key_name = match key_name {
Some(v) => match v.as_str() {
Some(s) => s,
None => unimplemented!("group_by with non-string key_name"),
},
None => "group",
};
let key_type = match key_type {
Some(ty) => match ty.downcast_object_ref::<crate::DataType>() {
Some(dt) => Some(dt.clone()),
None => {
// TODO: support DataType class instances
unimplemented!("group_by with non-string key_type")
}
},
None => None,
};
let table_set = self
.as_ref()
.group_by_key(key, key_name, key_type)
.map_err(|e| {
Error::new(ErrorKind::InvalidOperation, format!("Table.group_by: {e}"))View on GitHub (pinned to 0267ce9170)
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
Example fix
// before
table.call_method("group_by", kwargs!{"key_name" => Value::from(42)})
// after
table.call_method("group_by", kwargs!{"key_name" => Value::from("region")}) Defensive patterns
Strategy: type-guard
Validate before calling
let key_name_str = key_name.as_str().expect("key_name must be a string"); Type guard
fn is_str(v: &Value) -> bool { v.as_str().is_some() } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- group_by with non-string key_type
- distinct with non-string keys
- load_dataframe() for the Salesforce adapter
- list_relations_schemas_by_patterns for BigQuery
- ClickHouseAdapter::list_relations_schemas_by_patterns
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/1b81bc19d15e70e0.
Report an issue: GitHub.