{"id":"d7b709ff49e84e04","repo":"redis/redis-py","slug":"start-and-num-must-both-be-specified","errorCode":null,"errorMessage":"``start`` and ``num`` must both be specified","messagePattern":"``start`` and ``num`` must both be specified","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":5429,"sourceCode":"        ``get`` allows for returning items from external keys rather than the\n            sorted data itself.  Use an \"*\" to indicate where in the key\n            the item value is located\n\n        ``desc`` allows for reversing the sort\n\n        ``alpha`` allows for sorting lexicographically rather than numerically\n\n        ``store`` allows for storing the result of the sort into\n            the key ``store``\n\n        ``groups`` if set to True and if ``get`` contains at least two\n            elements, sort will return a list of tuples, each containing the\n            values fetched from the arguments to ``get``.\n\n        For more information, see https://redis.io/commands/sort\n        \"\"\"\n        if (start is not None and num is None) or (num is not None and start is None):\n            raise DataError(\"``start`` and ``num`` must both be specified\")\n\n        pieces: list[EncodableT] = [name]\n        if by is not None:\n            pieces.extend([b\"BY\", by])\n        if start is not None and num is not None:\n            pieces.extend([b\"LIMIT\", start, num])\n        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\")","sourceCodeStart":5411,"sourceCodeEnd":5447,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L5411-L5447","documentation":"Raised by sort() when exactly one of start/num is provided. They form the LIMIT clause together (LIMIT start num), so specifying a start offset without a count (or vice versa) is ambiguous and rejected before the command is built.","triggerScenarios":"Calling client.sort(key, start=0) without num, or client.sort(key, num=10) without start.","commonSituations":"Passing start from one config source and num from another where one is None; refactoring pagination code that dropped one argument.","solutions":["Provide both start and num together (e.g. sort(key, start=0, num=10)).","Omit both to return the full sorted set with no LIMIT.","Normalize pagination inputs so start/num are always a pair."],"exampleFix":"# before\nawait r.sort('mykey', start=0)\n# after\nawait r.sort('mykey', start=0, num=10)","handlingStrategy":"validation","validationCode":"def validate_sort_limit(start, num):\n    if (start is None) != (num is None):\n        raise ValueError('start and num must both be specified, or both omitted')\n    return True","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass start and num as a pair.","Build pagination as a (start, num) tuple and unpack together.","Omit both when you want the full result set."],"tags":["sort","pagination","validation","dataerror"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}