{"id":"424696bcaa91cbb1","repo":"redis/redis-py","slug":"ordering-obo-or-bulk-is-required-when-coun","errorCode":null,"errorMessage":"``ordering`` (OBO or BULK) is required when ``count`` is set","messagePattern":"``ordering`` \\(OBO or BULK\\) is required when ``count`` is set","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":3676,"sourceCode":"        ``EXACTLY`` moves exactly ``count`` elements or nothing at all. When\n        ``count`` is not given a single element is moved.\n\n        ``ordering`` controls the order at the destination: ``OBO`` pushes each\n        element as it is popped (reversing block order, stack semantics) while\n        ``BULK`` preserves the original relative order (queue semantics). It is\n        required whenever ``count`` is given.\n\n        Returns the array of moved elements, or ``None`` if nothing was moved.\n\n        For more information, see https://redis.io/commands/lmovem\n        \"\"\"\n        if count is None:\n            if mode is not None or ordering is not None:\n                raise DataError(\n                    \"``count`` is required when ``mode`` or ``ordering`` is set\"\n                )\n        elif ordering is None:\n            raise DataError(\n                \"``ordering`` (OBO or BULK) is required when ``count`` is set\"\n            )\n        pieces: list[EncodableT] = [first_list, second_list, src, dest]\n        if count is not None:\n            pieces.extend([mode or \"COUNT\", count, ordering])\n        return self.execute_command(\"LMOVEM\", *pieces)\n\n    @overload\n    def blmovem(\n        self: SyncClientProtocol,\n        first_list: str,\n        second_list: str,\n        timeout: float,\n        src: str = \"LEFT\",\n        dest: str = \"RIGHT\",\n        count: int | None = None,\n        mode: Literal[\"COUNT\", \"EXACTLY\"] | None = None,\n        ordering: Literal[\"OBO\", \"BULK\"] | None = None,","sourceCodeStart":3658,"sourceCodeEnd":3694,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L3658-L3694","documentation":"In lmovem(), when count is given the server requires an explicit ordering (OBO = pop-then-push stack semantics, BULK = preserve queue semantics). The guard at core.py:3675 raises DataError when count is set but ordering is None, because Redis LMOVEM rejects the command without it.","triggerScenarios":"r.lmovem('src','dst', count=3) with no ordering. The check fires before the command is sent.","commonSituations":"Assuming a default ordering; forgetting that the multi-element variant mandates an explicit choice; copy-pasting from LMOVE (single element) which has no ordering arg.","solutions":["Pass ordering='OBO' or ordering='BULK' whenever count is set.","Pick OBO to reverse block order (stack) or BULK to preserve relative order (queue) based on your list semantics.","Encapsulate the (count, ordering) pair in a helper so they are never supplied independently."],"exampleFix":"# before\nr.lmovem('src', 'dst', count=3)\n\n# after\nr.lmovem('src', 'dst', count=3, ordering='BULK')","handlingStrategy":"validation","validationCode":"if count is not None and ordering is None:\n    raise ValueError(\"lmovem: ordering ('OBO' or 'BULK') is required when count is set\")\nr.lmovem('src', 'dst', count=count, ordering=ordering)","typeGuard":"def valid_lmovem_ordering(count, ordering) -> bool:\n    return count is None or ordering in ('OBO', 'BULK')","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    r.lmovem('src', 'dst', count=3)\nexcept DataError as e:\n    if 'ordering' in str(e):\n        r.lmovem('src', 'dst', count=3, ordering='BULK')\n    else:\n        raise","preventionTips":["Always pair count with ordering; treat them as one logical argument.","Choose OBO (stack) vs BULK (queue) based on destination ordering needs."],"tags":["redis","lmovem","validation","parameter-conflict","lists"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}