{"record":{"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":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/connection.py","lineNumber":2581,"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":2563,"sourceCodeEnd":2599,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/connection.py#L2563-L2599","documentation":"Raised as ValueError by update_maint_notifications_config when maintenance notifications are currently enabled (maint_notifications_enabled() is True) and the caller passes a MaintNotificationsConfig with enabled=False. Disabling maintenance notifications at runtime is intentionally unsupported — once a pool is wired for them, connections and handlers are bound and cannot be cleanly torn down by a config flip.","triggerScenarios":"Calling pool.update_maint_notifications_config(MaintNotificationsConfig(enabled=False)) after the pool was created with maintenance notifications enabled (including the RESP3 default auto-enable).","commonSituations":"Toggling maintenance notifications off at runtime via a config update. Feature-flag flip that calls update_maint_notifications_config with a disabled config.","solutions":["To 'disable', create a fresh pool/client without maintenance notifications instead of flipping the existing pool's config.","Only call update_maint_notifications_config with a config whose enabled is True (adjusting other fields), or to switch handler modes.","Design feature flags to recreate the client rather than mutate an enabled pool."],"exampleFix":"# before\npool.update_maint_notifications_config(MaintNotificationsConfig(enabled=False))  # raises\n# after - recreate the pool instead\nnew_pool = ConnectionPool(maint_notifications_config=MaintNotificationsConfig(enabled=False))","handlingStrategy":"validation","validationCode":"def safe_update_maint_config(pool, new_cfg):\n    if pool.maint_notifications_enabled() and not getattr(new_cfg, 'enabled', True):\n        raise ValueError('Cannot disable maintenance notifications on an enabled pool; recreate it instead')\n    pool.update_maint_notifications_config(new_cfg)","typeGuard":null,"tryCatchPattern":"try:\n    pool.update_maint_notifications_config(new_cfg)\nexcept ValueError as e:\n    if 'Cannot disable maintenance notifications' in str(e):\n        pool = ConnectionPool(maint_notifications_config=new_cfg)  # recreate\n    else:\n        raise","preventionTips":["Never try to flip maintenance notifications off on an existing pool.","Design feature flags to recreate the client, not mutate the pool.","Only update other config fields on an enabled pool."],"tags":["maintenance-notifications","configuration","lifecycle"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}