{"id":"2cd86443d1a4b1a8","repo":"redis/redis-py","slug":"count-is-required-when-mode-or-ordering","errorCode":null,"errorMessage":"``count`` is required when ``mode`` or ``ordering`` is set","messagePattern":"``count`` is required when ``mode`` or ``ordering`` is set","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":3672,"sourceCode":"        ``LEFT`` (head) or ``RIGHT`` (tail).\n\n        When ``count`` is given, ``mode`` selects how many elements to move:\n        ``COUNT`` (the default) moves up to ``count`` elements, while\n        ``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\",","sourceCodeStart":3654,"sourceCodeEnd":3690,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L3654-L3690","documentation":"lmovem() atomically moves list elements. The multi-element form requires count, and mode/ordering are only meaningful when count is given. The guard at core.py:3671 raises DataError when count is None but mode or ordering was supplied, since those args have no effect for a single-element move.","triggerScenarios":"r.lmovem('src','dst', mode='COUNT') or r.lmovem('src','dst', ordering='OBO') without count. The single-element path (no count) ignores both.","commonSituations":"Building a move helper that always forwards mode/ordering; misunderstanding which args belong to the count variant.","solutions":["If you want multi-element move, supply count and ordering together.","If you want a single-element move, omit mode and ordering entirely.","Validate that mode/ordering are None whenever count is None before calling."],"exampleFix":"# before\nr.lmovem('src', 'dst', mode='COUNT')\n\n# after\nr.lmovem('src', 'dst', count=3, ordering='OBO')  # multi-element\n# or for single element:\nr.lmovem('src', 'dst')","handlingStrategy":"validation","validationCode":"if count is None and (mode is not None or ordering is not None):\n    raise ValueError('lmovem: mode/ordering require count')\nr.lmovem('src', 'dst', count=count, mode=mode, ordering=ordering)","typeGuard":"def valid_lmovem_args(count, mode, ordering) -> bool:\n    if count is None:\n        return mode is None and ordering is None\n    return True","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    r.lmovem('src', 'dst', mode=mode, ordering=ordering)\nexcept DataError as e:\n    if 'count is required' in str(e):\n        r.lmovem('src', 'dst')  # single-element move\n    else:\n        raise","preventionTips":["Keep count, mode, and ordering as a coupled group in your move helper.","For single-element moves, pass none of them."],"tags":["redis","lmovem","validation","parameter-conflict","lists"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}