{"record":{"id":"55c04028f08ba389","repo":"redis/redis-py","slug":"cannot-enable-maintenance-notifications-for-connec","errorCode":null,"errorMessage":"Cannot enable maintenance notifications for connection object that doesn't have a host attribute.","messagePattern":"Cannot enable maintenance notifications for connection object that doesn't have a host attribute\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/connection.py","lineNumber":401,"sourceCode":"            and self.maint_notifications_config\n            and self.maint_notifications_config.enabled\n            and self._maint_notifications_connection_handler\n            and host is not None\n        ):\n            await self._enable_maintenance_notifications(\n                maint_notifications_config=self.maint_notifications_config,\n                check_health=check_health,\n            )\n\n    async def _enable_maintenance_notifications(\n        self,\n        maint_notifications_config: MaintNotificationsConfig,\n        check_health: bool = True,\n    ) -> None:\n        try:\n            host = getattr(self, \"host\", None)\n            if host is None:\n                raise ValueError(\n                    \"Cannot enable maintenance notifications for connection\"\n                    \" object that doesn't have a host attribute.\"\n                )\n\n            endpoint_type = maint_notifications_config.get_endpoint_type(host, self)\n            await self.send_command(\n                \"CLIENT\",\n                \"MAINT_NOTIFICATIONS\",\n                \"ON\",\n                \"moving-endpoint-type\",\n                endpoint_type.value,\n                check_health=check_health,\n            )\n            response = await self.read_response()\n            if not response or str_if_bytes(response) != \"OK\":\n                raise ResponseError(\n                    \"The server doesn't support maintenance notifications\"\n                )","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/connection.py#L383-L419","documentation":"ValueError from Connection._enable_maintenance_notifications (redis/asyncio/connection.py:393) when the connection object has no 'host' attribute (host is None). The MAINT_NOTIFICATIONS command needs an endpoint type derived from the host; a connection without one (some internal/specialized connection types) cannot enable the feature. This is effectively an internal precondition failure.","triggerScenarios":"Enabling maintenance notifications on a connection type that does not carry a host attribute (e.g. a wrapped or mock connection); pool handing the enable call to a connection subclass missing host.","commonSituations":"Testing with mock connections; custom connection subclasses used in multidb/failover paths.","solutions":["Provide a host attribute on the connection before enabling maintenance notifications","Use the standard connection classes that always set host","Disable maintenance notifications for connections that have no host"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if getattr(conn, 'host', None) is None:\n    raise ValueError('connection has no host; cannot enable maintenance notifications')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only enable maintenance notifications on connections that carry a host","Use the standard connection classes in production paths"],"tags":["async","connection","maintenance-notifications","internal"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}