{"record":{"id":"09808a3faa3d1ef6","repo":"redis/redis-py","slug":"groupby-is-not-allowed-when-multiple-aggregators-a","errorCode":null,"errorMessage":"GROUPBY is not allowed when multiple aggregators are specified","messagePattern":"GROUPBY is not allowed when multiple aggregators are specified","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/timeseries/commands.py","lineNumber":1420,"sourceCode":"        filter_by_ts: List[int] | None,\n        filter_by_min_value: int | None,\n        filter_by_max_value: int | None,\n        groupby: str | None,\n        reduce: str | None,\n        select_labels: List[str] | None,\n        align: int | str | None,\n        latest: bool | None,\n        bucket_timestamp: str | None,\n        empty: bool | None,\n        exclude_empty: bool | None,\n    ):\n        \"\"\"Create TS.MRANGE and TS.MREVRANGE arguments.\"\"\"\n        if (\n            groupby is not None\n            and isinstance(aggregation_type, list)\n            and len(aggregation_type) > 1\n        ):\n            raise DataError(\n                \"GROUPBY is not allowed when multiple aggregators are specified\"\n            )\n        if exclude_empty and groupby is not None:\n            raise DataError(\"EXCLUDEEMPTY is not allowed with GROUPBY\")\n        params: list[EncodableT] = [from_time, to_time]\n        self._append_latest(params, latest)\n        self._append_filer_by_ts(params, filter_by_ts)\n        self._append_filer_by_value(params, filter_by_min_value, filter_by_max_value)\n        self._append_with_labels(params, with_labels, select_labels)\n        self._append_count(params, count)\n        self._append_align(params, align)\n        self._append_aggregation(params, aggregation_type, bucket_size_msec)\n        self._append_bucket_timestamp(params, bucket_timestamp)\n        self._append_empty(params, empty)\n        self._append_exclude_empty(params, exclude_empty)\n        params.extend([\"FILTER\"])\n        params += filters\n        self._append_groupby_reduce(params, groupby, reduce)","sourceCodeStart":1402,"sourceCodeEnd":1438,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/timeseries/commands.py#L1402-L1438","documentation":"Raised by the TS.MRANGE / TS.MREVRANGE parameter builder when groupby is set AND aggregation_type is a list with more than one entry. GROUPBY/REDUCE reduces multiple series into one bucket; combining it with multiple aggregators (a multi-aggregator spec) is semantically invalid and rejected client-side.","triggerScenarios":"Calling mrange(..., aggregation_type=['avg','max'], groupby='region', reduce='avg'). A list of aggregators with length > 1 plus any groupby value.","commonSituations":"Migrating from a single-aggregator call to the new multi-aggregator feature while still passing groupby. Copying NRANGE-style aggregator lists into an MRANGE with grouping.","solutions":["Drop groupby/reduce when you need multiple aggregators.","Use a single aggregator (string, or a one-element list) when you need GROUPBY.","Run two separate mrange calls if you need both multiple aggregators and grouping."],"exampleFix":"// before\nclient.ts().mrange(f, t, filters,\n    aggregation_type=['avg','max'], groupby='region', reduce='avg')\n// after  (choose one)\nclient.ts().mrange(f, t, filters,\n    aggregation_type='avg', groupby='region', reduce='avg')\n# or drop grouping for multi-aggregator\nclient.ts().mrange(f, t, filters, aggregation_type=['avg','max'])","handlingStrategy":"validation","validationCode":"if groupby and isinstance(aggregation_type, list) and len(aggregation_type) > 1:\n    raise ValueError('cannot combine groupby with multiple aggregators')\nclient.ts().mrange(...)","typeGuard":null,"tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.ts().mrange(..., aggregation_type=agg, groupby=groupby, reduce=reduce)\nexcept DataError:\n    agg = agg[0] if isinstance(agg, list) else agg\n    client.ts().mrange(..., aggregation_type=agg, groupby=groupby, reduce=reduce)","preventionTips":["Keep groupby and multi-aggregator lists mutually exclusive in wrappers.","Document the constraint where users configure mrange options."],"tags":["redistimeseries","mrange","groupby","aggregation","argument-validation"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}