{"record":{"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/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/core.py#L5411-L5447","documentation":"Raised by sort() when only one of start or num is provided. These two parameters together form the LIMIT clause for paging; specifying just one is invalid. The client checks that either both are set or both are None. It is a DataError.","triggerScenarios":"Calling client.sort(name, start=0) without num, or client.sort(name, num=10) without start.","commonSituations":"Adding pagination and forgetting the second argument, or conditionally passing start but hard-coding num elsewhere. Defaulting one to 0 and leaving the other as None.","solutions":["Provide both start and num together (e.g. start=0, num=10).","If you do not want paging, omit both start and num entirely."],"exampleFix":"# before\nclient.sort('mylist', start=0)\n\n# after\nclient.sort('mylist', start=0, num=10)","handlingStrategy":"validation","validationCode":"if (start is None) != (num is None):\n    raise ValueError('Provide both start and num, or neither')\nclient.sort(name, start=start, num=num)","typeGuard":null,"tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.sort(name, start=start, num=num)\nexcept DataError as e:\n    if 'must both be specified' in str(e):\n        start, num = (0, num) if num is not None else (start, 0)\n        client.sort(name, start=start, num=num)","preventionTips":["Treat start and num as a paired LIMIT tuple; set them together or leave both None.","When deriving paging from request query params, default both to None together."],"tags":["sort","pagination","validation","paired-arguments"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}