{"id":"a27997c54ab275b7","repo":"redis/redis-py","slug":"cannot-enable-maintenance-notifications-for-connec-a27997","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/connection.py","lineNumber":639,"sourceCode":"        if (\n            check_protocol_version(self.get_protocol(), 3)\n            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            self._enable_maintenance_notifications(\n                maint_notifications_config=self.maint_notifications_config,\n                check_health=check_health,\n            )\n\n    def _enable_maintenance_notifications(\n        self, maint_notifications_config: MaintNotificationsConfig, check_health=True\n    ):\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            else:\n                endpoint_type = maint_notifications_config.get_endpoint_type(host, self)\n                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 = 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":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/connection.py#L621-L657","documentation":"Raised by _enable_maintenance_notifications when the connection object has no 'host' attribute (getattr returns None). Maintenance notifications are host-based (they track a moving endpoint), so a connection with no resolvable host cannot register them. This most often surfaces with connection types that do not set a TCP host (e.g. a UnixDomainSocketConnection or a custom/mock connection). The exception is a ValueError thrown at connection setup time when maint_notifications_config is enabled.","triggerScenarios":"Calling connect() on a connection that has maint_notifications_config.enabled set, where self.host is None. This includes UnixDomainSocketConnection (uses a path, not a host) or any Connection subclass that overrides/removes the host attribute while maintenance notifications are enabled via the client config.","commonSituations":"Configuring a client over a Unix domain socket (unix_socket_path) while maintenance notifications are turned on; passing a maint_notifications_config to a connection type that does not expose host; unit tests using mock/fake connections without setting host.","solutions":["Disable maintenance notifications (do not enable maint_notifications_config) for non-TCP / Unix socket connections.","Use a TCP connection (Redis(host=...)) if you need maintenance notifications.","If using a custom Connection subclass, ensure it exposes a valid 'host' attribute before enabling maint notifications."],"exampleFix":"// before\nclient = redis.Redis(unix_socket_path='/tmp/redis.sock', maint_notifications_config=cfg)\nclient.ping()\n// after\nclient = redis.Redis(unix_socket_path='/tmp/redis.sock')  # maint notifications off for UDS","handlingStrategy":"validation","validationCode":"from redis.connection import Connection\nif getattr(conn, 'host', None) is None:\n    raise ValueError('Connection has no host; disable maint_notifications_config for this connection type')\nconn.connect()","typeGuard":"def supports_maint_notifications_by_host(conn) -> bool:\n    return getattr(conn, 'host', None) is not None","tryCatchPattern":"try:\n    client.ping()\nexcept ValueError as e:\n    if 'host attribute' in str(e):\n        # disable maintenance notifications and retry\n        pass","preventionTips":["Do not enable maint_notifications_config on UnixDomainSocketConnection or other non-host connection types.","Verify a connection exposes 'host' before enabling maintenance notifications."],"tags":["maintenance-notifications","configuration","unix-socket"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}