redis/redis-py · error · ValueError

Both ignore_max_time_diff and ignore_max_val_diff must be…

Error message

Both ignore_max_time_diff and ignore_max_val_diff must be set.

What it means

Raised by _append_insertion_filters when exactly one of ignore_max_time_diff / ignore_max_val_diff is provided. The TS.IGNORE clause requires both a max time difference and a max value difference; setting only one is a caller bug. Note this is a ValueError, not a DataError.

Solutions

  1. Set both ignore_max_time_diff and ignore_max_val_diff together.
  2. Omit both if you do not want insertion filtering.
  3. Pair them in a single config object so they are always supplied together.

Example fix

// before
client.ts().add(key, ts, value,
    ignore_max_time_diff=1000)  # missing val diff
// after
client.ts().add(key, ts, value,
    ignore_max_time_diff=1000, ignore_max_val_diff=5.0)
Defensive patterns

Strategy: validation

Validate before calling

if (ignore_max_time_diff is None) != (ignore_max_val_diff is None):
    raise ValueError('set both ignore_* or neither')
client.ts().add(key, ts, value,
    ignore_max_time_diff=ignore_max_time_diff,
    ignore_max_val_diff=ignore_max_val_diff)

Try / catch

try:
    client.ts().add(key, ts, value,
        ignore_max_time_diff=td, ignore_max_val_diff=vd)
except ValueError:
    client.ts().add(key, ts, value)

Prevention

When it happens

Trigger: Calling a TS.ADD-style insert with ignore_max_time_diff=1000 but ignore_max_val_diff unset, or vice-versa.

Common situations: Config that exposes only one of the two IGNORE knobs. Copying a partial example. Renaming one parameter during a refactor.

Related errors


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

Appendix: source

Thrown at redis/commands/timeseries/commands.py:2137

        """Append EMPTY property to params."""
        if empty:
            params.append("EMPTY")

    @staticmethod
    def _append_exclude_empty(params: list[EncodableT], exclude_empty: bool | None):
        """Append EXCLUDEEMPTY property to params."""
        if exclude_empty:
            params.append("EXCLUDEEMPTY")

    @staticmethod
    def _append_insertion_filters(
        params: list[EncodableT],
        ignore_max_time_diff: int | None = None,
        ignore_max_val_diff: Number | None = None,
    ):
        """Append insertion filters to params."""
        if (ignore_max_time_diff is None) != (ignore_max_val_diff is None):
            raise ValueError(
                "Both ignore_max_time_diff and ignore_max_val_diff must be set."
            )

        if ignore_max_time_diff is not None and ignore_max_val_diff is not None:
            params.extend(
                ["IGNORE", str(ignore_max_time_diff), str(ignore_max_val_diff)]
            )

View on GitHub (pinned to 6a6b581b48)