{"id":"abbb71cb2c2f08bf","repo":"redis/redis-py","slug":"the-only-valid-subcommands-are","errorCode":null,"errorMessage":"The only valid subcommands are ","messagePattern":"The only valid subcommands are ","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/json/commands.py","lineNumber":826,"sourceCode":"        subcommand: str,\n        key: str | None = None,\n        path: str | None = Path.root_path(),\n    ) -> Awaitable[int | list[str]]: ...\n\n    def debug(\n        self,\n        subcommand: str,\n        key: str | None = None,\n        path: str | None = Path.root_path(),\n    ) -> (int | list[str]) | Awaitable[int | list[str]]:\n        \"\"\"Return the memory usage in bytes of a value under ``path`` from\n        key ``name``.\n\n        For more information see `JSON.DEBUG <https://redis.io/commands/json.debug>`_.\n        \"\"\"  # noqa\n        valid_subcommands = [\"MEMORY\", \"HELP\"]\n        if subcommand not in valid_subcommands:\n            raise DataError(\"The only valid subcommands are \", str(valid_subcommands))\n        pieces = [subcommand]\n        if subcommand == \"MEMORY\":\n            if key is None:\n                raise DataError(\"No key specified\")\n            pieces.append(key)\n            pieces.append(str(path))\n        return self.execute_command(\"JSON.DEBUG\", *pieces)\n\n    @overload\n    def jsonget(self: SyncClientProtocol, *args, **kwargs) -> JsonType | None: ...\n\n    @overload\n    def jsonget(\n        self: AsyncClientProtocol, *args, **kwargs\n    ) -> Awaitable[JsonType | None]: ...\n\n    @deprecated_function(\n        version=\"4.0.0\", reason=\"redisjson-py supported this, call get directly.\"","sourceCodeStart":808,"sourceCodeEnd":844,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/json/commands.py#L808-L844","documentation":"Raised by JSON.debug() when subcommand is not in ['MEMORY', 'HELP']. JSON.DEBUG only has two subcommands. Note the message is malformed: DataError is constructed with two positional args (\"The only valid subcommands are \", str(valid_subcommands)), so str(exc) includes both as a tuple representation rather than a clean sentence.","triggerScenarios":"Call client.json().debug(subcommand) with subcommand not equal to 'MEMORY' or 'HELP' (case-sensitive), e.g. debug('SEGMENTS') or debug('memory') (lowercase).","commonSituations":"Guessing a subcommand name; case mismatch ('memory' vs 'MEMORY'); porting code from another client with different subcommand names.","solutions":["Use subcommand='MEMORY' (requires a key) or subcommand='HELP'.","Uppercase the input: subcommand = subcommand.upper().","If you need memory usage, call debug('MEMORY', key)."],"exampleFix":"// before\nclient.json().debug('memory', 'mykey')\n// after\nclient.json().debug('MEMORY', 'mykey')","handlingStrategy":"validation","validationCode":"VALID = {\"MEMORY\", \"HELP\"}\n\ndef json_debug(client, subcommand, key=None, path=None):\n    subcommand = subcommand.upper()\n    if subcommand not in VALID:\n        raise ValueError(f\"subcommand must be one of {VALID}, got {subcommand!r}\")\n    return client.json().debug(subcommand, key, path) if subcommand == \"MEMORY\" \\\n        else client.json().debug(subcommand)","typeGuard":"def is_valid_debug_subcommand(v) -> bool:\n    return isinstance(v, str) and v.upper() in {\"MEMORY\", \"HELP\"}","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.json().debug(subcommand, key)\nexcept DataError as e:\n    if \"valid subcommands\" in str(e):\n        client.json().debug(subcommand.upper(), key)\n    else:\n        raise","preventionTips":["Always uppercase user-supplied subcommands before calling debug().","Keep a constant set of valid subcommands next to your JSON wrapper.","Use debug('HELP') from a CLI to discover the surface."],"tags":["redis-json","validation","json-debug","dataerror"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}