redis/redis-py · error · DataError
with_labels and select_labels cannot be provided together.
Error message
with_labels and select_labels cannot be provided together.
What it means
Raised by _append_with_labels (used by TS.MRANGE / TS.MGET family) when both with_labels=True and a non-empty select_labels are supplied. WITHLABELS returns all labels; SELECTED_LABELS returns a subset — they are mutually exclusive on the wire.
Solutions
- Use with_labels=True alone for all labels.
- Use select_labels=[...] alone for a subset of labels.
- Ensure with_labels is False/None whenever select_labels is provided.
Example fix
// before
client.ts().mrange(f, t, filters,
with_labels=True, select_labels=['region'])
// after
client.ts().mrange(f, t, filters, select_labels=['region'])
# or
client.ts().mrange(f, t, filters, with_labels=True) Defensive patterns
Strategy: validation
Validate before calling
if select_labels:
with_labels = False
client.ts().mrange(..., with_labels=with_labels, select_labels=select_labels) Try / catch
from redis.exceptions import DataError
try:
client.ts().mrange(..., with_labels=with_labels, select_labels=select_labels)
except DataError:
client.ts().mrange(..., select_labels=select_labels) Prevention
- Never set with_labels and select_labels together.
- Default with_labels to False when select_labels is populated.
When it happens
Trigger: Calling mrange(..., with_labels=True, select_labels=['region']) or mget with both set.
Common situations: A shared kwargs dict where with_labels defaults to True and select_labels is also populated. Wrapper code that sets both 'to be safe'.
Related errors
- EXCLUDEEMPTY is not allowed with GROUPBY
- GROUPBY is not allowed when multiple aggregators are…
- AGGREGATION requires exactly one aggregation spec per key
- At least one key must be provided.
- block_min_count requires block_milliseconds to be set; the…
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/de57d97eb7c59190.
Report an issue: GitHub.
Appendix: source
Thrown at redis/commands/timeseries/commands.py:1947
)
params.append("FILTER")
params.extend(filters)
@staticmethod
def _append_uncompressed(params: list[EncodableT], uncompressed: bool | None):
"""Append UNCOMPRESSED tag to params."""
if uncompressed:
params.extend(["ENCODING", "UNCOMPRESSED"])
@staticmethod
def _append_with_labels(
params: list[EncodableT],
with_labels: bool | None,
select_labels: list[str] | None,
):
"""Append labels behavior to params."""
if with_labels and select_labels:
raise DataError(
"with_labels and select_labels cannot be provided together."
)
if with_labels:
params.extend(["WITHLABELS"])
if select_labels:
params.extend(["SELECTED_LABELS", *select_labels])
@staticmethod
def _append_groupby_reduce(
params: list[EncodableT], groupby: str | None, reduce: str | None
):
"""Append GROUPBY REDUCE property to params."""
if groupby is not None and reduce is not None:
params.extend(["GROUPBY", groupby, "REDUCE", reduce.upper()])
@staticmethod
def _append_retention(params: list[EncodableT], retention: int | None):View on GitHub (pinned to 6a6b581b48)