{"record":{"id":"932bde4ea5e8f477","repo":"redis/redis-py","slug":"pattern-pattern-has-no-handler-registered-932bde","errorCode":null,"errorMessage":"Pattern '{pattern}' has no handler registered","messagePattern":"Pattern '(.+?)' has no handler registered","errorType":"exception","errorClass":"RedisError","httpStatus":null,"severity":"error","filePath":"redis/keyspace_notifications.py","lineNumber":1728,"sourceCode":"        \"\"\"\n        while self.subscribed:\n            notification = self.get_message(timeout=1.0)\n            if notification is not None:\n                yield notification\n\n    @property\n    def subscribed(self) -> bool:\n        \"\"\"Check if there are any active subscriptions and not closed.\"\"\"\n        return not self._closed and self._pubsub.subscribed\n\n    def _validate_all_handlers(self) -> None:\n        \"\"\"Raise if any subscription in the underlying PubSub lacks a handler.\"\"\"\n        for channel, handler in self._pubsub.channels.items():\n            if handler is None:\n                raise RedisError(f\"Channel '{channel}' has no handler registered\")\n        for pattern, handler in self._pubsub.patterns.items():\n            if handler is None:\n                raise RedisError(f\"Pattern '{pattern}' has no handler registered\")\n\n    def close(self):\n        \"\"\"Close the pubsub connection and clean up resources.\"\"\"\n        self._closed = True\n        try:\n            self._pubsub.close()\n        except Exception:\n            pass\n\n\n# =============================================================================\n# Cluster-Aware Keyspace Notification Manager\n# =============================================================================\n\n\nclass ClusterKeyspaceNotifications(AbstractKeyspaceNotifications):\n    \"\"\"\n    Manages keyspace notification subscriptions across all nodes in a Redis Cluster.","sourceCodeStart":1710,"sourceCodeEnd":1746,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/keyspace_notifications.py#L1710-L1746","documentation":"KeyspaceNotifications._validate_all_handlers (redis/keyspace_notifications.py:1728, standalone) raises RedisError when any pattern subscription (psubscribe) has a None handler. Same lifecycle as error 432 but for glob-pattern subscriptions. run_in_thread needs a callable per pattern to dispatch incoming messages.","triggerScenarios":"notifications.subscribe(KeyspacePattern('user:*'), handler=None) then run_in_thread; subscribing a pattern for listen()/get_message() use and then switching to run_in_thread without a handler.","commonSituations":"Same as 432 for pattern-based subscriptions; forgetting handler on a KeyspacePattern subscribe.","solutions":["Pass a handler for every pattern subscription before run_in_thread.","Use get_message()/listen() if you intend to handle messages inline without per-pattern callbacks.","Audit all subscribe calls so every KeyspacePattern has a non-None handler."],"exampleFix":"// before\nnotifications.subscribe(KeyspacePattern('user:*'))\nnotifications.run_in_thread()\n// after\nnotifications.subscribe(KeyspacePattern('user:*'), handler=on_user_event)\nnotifications.run_in_thread(poll_timeout=0.1)","handlingStrategy":"validation","validationCode":"def all_patterns_have_handler(ksn) -> bool:\n    return all(h is not None for _, h in ksn._pubsub.patterns.items())","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a handler for every pattern subscription before run_in_thread.","Use get_message()/listen() if you handle messages inline.","Ensure every KeyspacePattern subscribe includes a non-None handler."],"tags":["keyspace-notifications","pubsub","handler","pattern","standalone"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}