{"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":"validation","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/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/asyncio/connection.py#L383-L419","documentation":"Raised as ValueError in _enable_maintenance_notifications when getattr(self,'host',None) is None. The CLIENT MAINT_NOTIFICATIONS ON command needs an endpoint type resolved from the connection's host, so a connection without a host attribute (e.g. some mock/test doubles or unix-socket-only paths) cannot enable notifications.","triggerScenarios":"Constructing a Connection subclass that doesn't set self.host (or sets it to None) while maintenance notifications are enabled and protocol=3, then triggering the on_connect health-check path that calls _enable_maintenance_notifications.","commonSituations":"Using a Connection subclass for testing, or a custom transport (e.g. in-memory, unix socket configured differently) that never assigns host; passing a Connection into a context that expects maintenance notifications without a real host.","solutions":["Ensure self.host is set on the connection (provide host= when constructing, or set it in your subclass before connect).","Disable maintenance notifications for connections that legitimately have no host (tests, in-memory transports).","If using unix sockets or unusual transports, configure them so host resolves to a usable endpoint identifier."],"exampleFix":"// before\nclass TestConn(AsyncConnection):\n    def __init__(self, *a, **kw):\n        super().__init__(*a, host=None, **kw)  # later raises [92]\n// after\nclass TestConn(AsyncConnection):\n    def __init__(self, *a, **kw):\n        super().__init__(*a, host='127.0.0.1', **kw)","handlingStrategy":"validation","validationCode":"if cfg.enabled and getattr(conn, 'host', None) is None:\n    raise ValueError('Connection needs a host to enable maintenance notifications')","typeGuard":null,"tryCatchPattern":"try:\n    await conn.connect()\nexcept ValueError as e:\n    if \"doesn't have a host attribute\" in str(e):\n        conn.host = '127.0.0.1'; await conn.connect()","preventionTips":["Always set host= on Connection (and subclass) instances.","Disable maintenance notifications for host-less test connections."],"tags":["connection","maintenance-notifications","host","subclassing"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}