{"id":"c198883817a33c79","repo":"redis/redis-py","slug":"to-configure-maintenance-notifications-a-parser-m-c19888","errorCode":null,"errorMessage":"To configure maintenance notifications, a parser must be provided!","messagePattern":"To configure maintenance notifications, a parser must be provided!","errorType":"exception","errorClass":"RedisError","httpStatus":null,"severity":"error","filePath":"redis/connection.py","lineNumber":486,"sourceCode":"        parser: Optional[BaseParser] = None,\n    ):\n        \"\"\"\n        Enable maintenance notifications by setting up\n        handlers and storing original connection parameters.\n\n        Should be used ONLY with parsers that support push notifications.\n        \"\"\"\n        if (\n            not self.maint_notifications_config\n            or not self.maint_notifications_config.enabled\n        ):\n            self._maint_notifications_pool_handler = None\n            self._maint_notifications_connection_handler = None\n            self._oss_cluster_maint_notifications_handler = None\n            return\n\n        if not parser:\n            raise RedisError(\n                \"To configure maintenance notifications, a parser must be provided!\"\n            )\n\n        if not isinstance(parser, _HiredisParser) and not isinstance(\n            parser, _RESP3Parser\n        ):\n            raise RedisError(\n                \"Maintenance notifications are only supported with hiredis and RESP3 parsers!\"\n            )\n\n        if maint_notifications_pool_handler:\n            # Extract a reference to a new pool handler that copies all properties\n            # of the original one and has a different connection reference\n            # This is needed because when we attach the handler to the parser\n            # we need to make sure that the handler has a reference to the\n            # connection that the parser is attached to.\n            self._maint_notifications_pool_handler = (\n                maint_notifications_pool_handler.get_handler_for_connection()","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/connection.py#L468-L504","documentation":"Raised by AbstractConnection._configure_maintenance_notifications when maintenance notifications are enabled in config but no parser instance was passed to the method. The parser is required to wire push-notification handling. This is primarily an internal/programmatic error: the connection plumbing did not supply the parser when enabling notifications. Raised as a generic RedisError.","triggerScenarios":"Calling connection._configure_maintenance_notifications(...) with a config whose .enabled is True but parser=None. Typically hit by custom connection subclasses or reconnection paths that forgot to forward the parser, not by normal client construction.","commonSituations":"Subclassing AbstractConnection and overriding/replaying reconnection logic without passing the parser; manually invoking the config method during custom pool wiring; a bug in a fork/monkeypatch of the connection layer.","solutions":["Pass the connection's parser when enabling notifications: _configure_maintenance_notifications(..., parser=self._get_parser()).","Use the standard client construction path (RedisCluster with maint_notifications_config) instead of calling the internal method directly.","If notifications are not actually needed, disable them so the method early-returns before the parser check."],"exampleFix":"// before\nconn._configure_maintenance_notifications(cfg, parser=None)\n// after\nconn._configure_maintenance_notifications(cfg, parser=conn._get_parser())","handlingStrategy":"validation","validationCode":"def configure_maint(conn, cfg, parser=None):\n    if cfg and getattr(cfg, 'enabled', False) and parser is None:\n        parser = conn._get_parser()\n    conn._configure_maintenance_notifications(cfg, parser=parser)","typeGuard":"def parser_supplied(parser) -> bool:\n    return parser is not None","tryCatchPattern":"try:\n    conn._configure_maintenance_notifications(cfg, parser=None)\nexcept Exception as e:\n    if 'a parser must be provided' in str(e):\n        conn._configure_maintenance_notifications(cfg, parser=conn._get_parser())\n    else:\n        raise","preventionTips":["Avoid calling _configure_maintenance_notifications directly; use standard client construction.","If you must, always forward parser=self._get_parser().","Disable notifications in config when not needed."],"tags":["connection","parser","maintenance-notifications","internal","config"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}