{"record":{"id":"d760270f9fceac3d","repo":"redis/redis-py","slug":"when-using-groups-the-get-argument-must-be-spe","errorCode":null,"errorMessage":"when using \"groups\" the \"get\" argument must be specified and contain at least two keys","messagePattern":"when using \"groups\" the \"get\" argument must be specified and contain at least two keys","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":5454,"sourceCode":"        if get is not None:\n            # If get is a string assume we want to get a single value.\n            # Otherwise assume it's an iterable and we want to get multiple\n            # values. We can't just iterate blindly because strings are\n            # iterable.\n            if isinstance(get, (bytes, str)):\n                pieces.extend([b\"GET\", get])\n            else:\n                for g in get:\n                    pieces.extend([b\"GET\", g])\n        if desc:\n            pieces.append(b\"DESC\")\n        if alpha:\n            pieces.append(b\"ALPHA\")\n        if store is not None:\n            pieces.extend([b\"STORE\", store])\n        if groups:\n            if not get or isinstance(get, (bytes, str)) or len(get) < 2:\n                raise DataError(\n                    'when using \"groups\" the \"get\" argument '\n                    \"must be specified and contain at least \"\n                    \"two keys\"\n                )\n\n        options = {\"groups\": len(get) if groups else None}\n        options[\"keys\"] = [name]\n        return self.execute_command(\"SORT\", *pieces, **options)\n\n    @overload\n    def sort_ro(\n        self: SyncClientProtocol,\n        key: str,\n        start: int | None = None,\n        num: int | None = None,\n        by: str | None = None,\n        get: list[str] | None = None,\n        desc: bool = False,","sourceCodeStart":5436,"sourceCodeEnd":5472,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/core.py#L5436-L5472","documentation":"Raised by sort() when groups=True but the get argument is missing, is a single string/bytes, or has fewer than two entries. The groups option restructures output into tuples built from multiple GET patterns, so at least two GET keys are required. It is a DataError.","triggerScenarios":"Calling client.sort(name, groups=True) with no get; client.sort(name, groups=True, get='field_*'); or client.sort(name, groups=True, get=['only_one']).","commonSituations":"Enabling groups for tuple-style results but providing a single GET pattern, or forgetting the get argument entirely after copying a groups example.","solutions":["Pass get as a list with at least two patterns, e.g. get=['name_*', 'score_*'], together with groups=True.","If you only need a single GET projection, drop groups=True and accept a flat list."],"exampleFix":"# before\nclient.sort('users', groups=True, get='name_*')\n\n# after\nclient.sort('users', groups=True, get=['name_*', 'score_*'])","handlingStrategy":"validation","validationCode":"if groups:\n    if not get or isinstance(get, (str, bytes)) or len(list(get)) < 2:\n        raise ValueError('groups=True requires get to be a list of >= 2 keys')\nclient.sort(name, get=get, groups=groups)","typeGuard":null,"tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.sort(name, get=get, groups=groups)\nexcept DataError as e:\n    if 'must be specified' in str(e):\n        groups = False\n        client.sort(name, get=get, groups=groups)","preventionTips":["Only enable groups=True when you pass get as a list of two or more patterns.","If you need a single projection, omit groups and accept a flat list."],"tags":["sort","groups","get-projection","validation"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}