redis/redis-py · error · DataError

ACL LOG count must be an integer

Error message

ACL LOG count must be an integer

What it means

Raised by Redis.acl_log() when the `count` argument is supplied but is not an instance of int. The library explicitly type-checks count with isinstance(count, int) before appending it to the ACL LOG command arguments; a bool True/False would pass (bool is a subclass of int) but strings, floats, or None-with-typing are rejected. This guards the wire format, which requires an integer count.

Solutions

  1. Coerce count to int before calling: client.acl_log(count=int(count_str)).
  2. Omit count (or pass None) to fetch all log entries.
  3. Validate the source value and surface a clearer error to the caller.

Example fix

# before
client.acl_log(count=request.args.get('count'))  # string from HTTP
# after
client.acl_log(count=int(request.args.get('count')))
Defensive patterns

Strategy: validation

Validate before calling

def safe_acl_log(client, count=None):
    if count is not None and not isinstance(count, int):
        count = int(count)
    return client.acl_log(count=count)

Type guard

def is_int_count(count) -> bool:
    # note: bool is a subclass of int and passes isinstance; reject bool explicitly if undesired
    return count is None or (isinstance(count, int) and not isinstance(count, bool))

Try / catch

from redis.exceptions import DataError
try:
    logs = client.acl_log(count=count)
except DataError as e:
    if 'must be an integer' in str(e):
        logs = client.acl_log(count=int(count))
    else:
        raise

Prevention

When it happens

Trigger: Calling client.acl_log(count='10') with a string, count=10.5 with a float, or count=[10] with a list. Passing count=None does NOT trigger this (None short-circuits the check) but a truthy non-int does.

Common situations: Loading count from a config file/env var as a string and passing it through without coercion; reading a query parameter in a web handler and forwarding it as-is.

Related errors


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

Appendix: source

Thrown at redis/commands/core.py:291

    @overload
    def acl_log(
        self: AsyncClientProtocol, count: int | None = None, **kwargs
    ) -> Awaitable[ACLLogData]: ...

    def acl_log(
        self, count: int | None = None, **kwargs
    ) -> ACLLogData | Awaitable[ACLLogData]:
        """
        Get ACL logs as a list.
        :param int count: Get logs[0:count].
        :rtype: List.

        For more information, see https://redis.io/commands/acl-log
        """
        args = []
        if count is not None:
            if not isinstance(count, int):
                raise DataError("ACL LOG count must be an integer")
            args.append(count)

        return self.execute_command("ACL LOG", *args, **kwargs)

    @overload
    def acl_log_reset(self: SyncClientProtocol, **kwargs) -> bool: ...

    @overload
    def acl_log_reset(self: AsyncClientProtocol, **kwargs) -> Awaitable[bool]: ...

    def acl_log_reset(self, **kwargs) -> bool | Awaitable[bool]:
        """
        Reset ACL logs.
        :rtype: Boolean.

        For more information, see https://redis.io/commands/acl-log
        """
        args = [b"RESET"]

View on GitHub (pinned to 6a6b581b48)