{"id":"de57d97eb7c59190","repo":"redis/redis-py","slug":"with-labels-and-select-labels-cannot-be-provided-t","errorCode":null,"errorMessage":"with_labels and select_labels cannot be provided together.","messagePattern":"with_labels and select_labels cannot be provided together\\.","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/timeseries/commands.py","lineNumber":1947,"sourceCode":"            )\n        params.append(\"FILTER\")\n        params.extend(filters)\n\n    @staticmethod\n    def _append_uncompressed(params: list[EncodableT], uncompressed: bool | None):\n        \"\"\"Append UNCOMPRESSED tag to params.\"\"\"\n        if uncompressed:\n            params.extend([\"ENCODING\", \"UNCOMPRESSED\"])\n\n    @staticmethod\n    def _append_with_labels(\n        params: list[EncodableT],\n        with_labels: bool | None,\n        select_labels: list[str] | None,\n    ):\n        \"\"\"Append labels behavior to params.\"\"\"\n        if with_labels and select_labels:\n            raise DataError(\n                \"with_labels and select_labels cannot be provided together.\"\n            )\n\n        if with_labels:\n            params.extend([\"WITHLABELS\"])\n        if select_labels:\n            params.extend([\"SELECTED_LABELS\", *select_labels])\n\n    @staticmethod\n    def _append_groupby_reduce(\n        params: list[EncodableT], groupby: str | None, reduce: str | None\n    ):\n        \"\"\"Append GROUPBY REDUCE property to params.\"\"\"\n        if groupby is not None and reduce is not None:\n            params.extend([\"GROUPBY\", groupby, \"REDUCE\", reduce.upper()])\n\n    @staticmethod\n    def _append_retention(params: list[EncodableT], retention: int | None):","sourceCodeStart":1929,"sourceCodeEnd":1965,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/timeseries/commands.py#L1929-L1965","documentation":"Raised by _append_with_labels when both with_labels=True and select_labels (a non-empty list) are supplied to TS.MRANGE/TS.MREVRANGE. WITHLABELS returns all label-value pairs while SELECTED_LABELS returns only a subset; they are mutually exclusive on the wire. Choose one.","triggerScenarios":"client.ts().mrange('-', '+', filters=f, with_labels=True, select_labels=['region']).","commonSituations":"Enabling WITHLABELS globally via config while also passing a select_labels list for a specific call; merging option dicts that each set one of the two; upgrading code that used select_labels and then turned on with_labels.","solutions":["Use select_labels alone to return a subset: with_labels=False, select_labels=['region'].","Use with_labels=True alone to return all labels: drop select_labels.","If assembling options dynamically, enforce mutual exclusion before the call."],"exampleFix":"// before\nclient.ts().mrange('-', '+', filters=f, with_labels=True, select_labels=['region'])\n// after\nclient.ts().mrange('-', '+', filters=f, with_labels=False, select_labels=['region'])","handlingStrategy":"validation","validationCode":"def normalize_labels(with_labels, select_labels):\n    if with_labels and select_labels:\n        return False, select_labels  # prefer the subset\n    return with_labels, select_labels","typeGuard":"def labels_compatible(with_labels, select_labels) -> bool:\n    return not (with_labels and select_labels)","tryCatchPattern":"try:\n    client.ts().mrange('-', '+', filters=f, with_labels=wl, select_labels=sl)\nexcept Exception as e:\n    if 'cannot be provided together' in str(e):\n        client.ts().mrange('-', '+', filters=f, select_labels=sl)\n    else:\n        raise","preventionTips":["Treat with_labels and select_labels as mutually exclusive.","Default one of them to its disabled value in shared config.","Validate before assembling the call."],"tags":["redistimeseries","timeseries","mrange","labels","argument-error"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}