{"id":"f2ed172224d477b8","repo":"redis/redis-py","slug":"cannot-disable-maintenance-notifications-after-ena-f2ed17","errorCode":null,"errorMessage":"Cannot disable maintenance notifications after enabling them","messagePattern":"Cannot disable maintenance notifications after enabling them","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/connection.py","lineNumber":2566,"sourceCode":"    def update_maint_notifications_config(\n        self,\n        maint_notifications_config: MaintNotificationsConfig,\n        oss_cluster_maint_notifications_handler: Optional[\n            OSSMaintNotificationsHandler\n        ] = None,\n    ):\n        \"\"\"\n        Updates the maintenance notifications configuration.\n        This method should be called only if the pool was created\n        without enabling the maintenance notifications and\n        in a later point in time maintenance notifications\n        are requested to be enabled.\n        \"\"\"\n        if (\n            self.maint_notifications_enabled()\n            and not maint_notifications_config.enabled\n        ):\n            raise ValueError(\n                \"Cannot disable maintenance notifications after enabling them\"\n            )\n        if oss_cluster_maint_notifications_handler:\n            self._oss_cluster_maint_notifications_handler = (\n                oss_cluster_maint_notifications_handler\n            )\n            # OSS cluster mode and pool-handler mode are mutually exclusive\n            # (see __init__). A pool created with the default RESP3 \"auto\"\n            # config wires a pool handler before this method runs; clear it so\n            # new and existing connections are not configured with both handlers.\n            self._maint_notifications_pool_handler = None\n        else:\n            # first update pool settings\n            if self._oss_cluster_maint_notifications_handler:\n                # Pool already in OSS cluster mode; update the OSS handler config\n                # instead of creating a mutually-exclusive pool handler (which\n                # would be silently ignored because the OSS handler wins priority\n                # in both update helpers below).","sourceCodeStart":2548,"sourceCodeEnd":2584,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/connection.py#L2548-L2584","documentation":"Raised as a ValueError by update_maint_notifications_config (connection.py:2562-2568) when maintenance notifications are currently enabled (maint_notifications_enabled() is True) and you pass a new MaintNotificationsConfig with enabled=False. The library treats enabling as a one-way operation on an existing pool; it will not tear down already-configured handlers/connections.","triggerScenarios":"Calling pool.update_maint_notifications_config(MaintNotificationsConfig(enabled=False)) on a pool that was created with notifications enabled (or previously updated to enabled). This is an explicit reconfiguration call, not the constructor.","commonSituations":"Dynamic config toggles that flip notifications on/off at runtime; reusing a long-lived pool and trying to disable notifications during a maintenance window or shutdown; config-driven code that re-applies a 'disabled' config unconditionally.","solutions":["Do not attempt to disable notifications on an already-enabled pool — create a new pool (without notifications) and switch clients to it instead.","If you need on/off toggling, design your app to recreate the pool/connection rather than mutate the existing one.","Guard the update call: only invoke update_maint_notifications_config when the desired enabled state differs AND you are enabling, not disabling."],"exampleFix":"# before\npool.update_maint_notifications_config(\n    MaintNotificationsConfig(enabled=False))  # raises if currently enabled\n\n# after: recreate the pool without notifications instead\npool.disconnect()\nclient.set_pool(redis.ConnectionPool(\n    protocol=3,\n    maint_notifications_config=MaintNotificationsConfig(enabled=False)))","handlingStrategy":"validation","validationCode":"if new_cfg.enabled is False and pool.maint_notifications_enabled():\n    raise ValueError(\"Cannot disable notifications on an enabled pool; recreate the pool instead.\")\n\npool.update_maint_notifications_config(new_cfg)","typeGuard":"def can_update_maint_config(pool, new_enabled: bool) -> bool:\n    return not (pool.maint_notifications_enabled() and new_enabled is False)","tryCatchPattern":"try:\n    pool.update_maint_notifications_config(new_cfg)\nexcept ValueError as e:\n    if \"Cannot disable\" in str(e):\n        # recreate pool instead of mutating\n        pool.disconnect()\n        pool = redis.ConnectionPool(protocol=3, maint_notifications_config=new_cfg)\n    else:\n        raise","preventionTips":["Treat maintenance-notification enabling as a pool-lifetime decision; recreate pools to change modes.","Guard dynamic config reapplication to skip disabling on already-enabled pools.","Keep a single source of truth for the enabled flag per pool lifecycle."],"tags":["maintenance-notifications","configuration","validation","lifecycle"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}