redis/redis-py · error · DataError

The only valid subcommands are

Error message

The only valid subcommands are 

What it means

Raised by JSON.DEBUG (redis/commands/json/commands.py:826) as a DataError when the subcommand argument is not 'MEMORY' or 'HELP'. Note the message itself is malformed: the call is `raise DataError('The only valid subcommands are ', str(valid_subcommands))` which passes the list as a second positional arg to DataError rather than embedding it in the message, so the rendered text is truncated and does not show the allowed values.

Solutions

  1. Use only 'MEMORY' (with a key) or 'HELP' as the subcommand.
  2. For 'MEMORY' you must also pass a key argument or you hit the separate 'No key specified' error (347).
  3. Pass the exact uppercase string; matching is case-sensitive.

Example fix

# before
client.json().debug('stats')
# after
client.json().debug('MEMORY', 'mykey')
Defensive patterns

Strategy: validation

Validate before calling

VALID_DEBUG_SUBCOMMANDS = {'MEMORY', 'HELP'}

def safe_json_debug(subcommand):
    sub = subcommand.upper()
    if sub not in VALID_DEBUG_SUBCOMMANDS:
        raise ValueError(f'JSON.DEBUG subcommand must be one of {sorted(VALID_DEBUG_SUBCOMMANDS)}')
    return sub

Type guard

def is_valid_debug_sub(s) -> bool:
    return isinstance(s, str) and s.upper() in {'MEMORY', 'HELP'}

Try / catch

from redis.exceptions import DataError
try:
    client.json().debug(sub)
except DataError:
    client.json().debug('HELP')  # discover supported subcommands

Prevention

When it happens

Trigger: Calling client.json().debug('STATS') or any subcommand string other than 'MEMORY' or 'HELP' (case-sensitive, must be uppercase).

Common situations: Assuming JSON.DEBUG supports subcommands from another Redis variant, passing lowercase 'memory', or guessing subcommand names. The unhelpful truncated message makes discovery harder.

Related errors


AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10). Data as JSON: /api/errors/abbb71cb2c2f08bf. Report an issue: GitHub.

Appendix: source

Thrown at redis/commands/json/commands.py:826

        subcommand: str,
        key: str | None = None,
        path: str | None = Path.root_path(),
    ) -> Awaitable[int | list[str]]: ...

    def debug(
        self,
        subcommand: str,
        key: str | None = None,
        path: str | None = Path.root_path(),
    ) -> (int | list[str]) | Awaitable[int | list[str]]:
        """Return the memory usage in bytes of a value under ``path`` from
        key ``name``.

        For more information see `JSON.DEBUG <https://redis.io/commands/json.debug>`_.
        """  # noqa
        valid_subcommands = ["MEMORY", "HELP"]
        if subcommand not in valid_subcommands:
            raise DataError("The only valid subcommands are ", str(valid_subcommands))
        pieces = [subcommand]
        if subcommand == "MEMORY":
            if key is None:
                raise DataError("No key specified")
            pieces.append(key)
            pieces.append(str(path))
        return self.execute_command("JSON.DEBUG", *pieces)

    @overload
    def jsonget(self: SyncClientProtocol, *args, **kwargs) -> JsonType | None: ...

    @overload
    def jsonget(
        self: AsyncClientProtocol, *args, **kwargs
    ) -> Awaitable[JsonType | None]: ...

    @deprecated_function(
        version="4.0.0", reason="redisjson-py supported this, call get directly."

View on GitHub (pinned to 6a6b581b48)