redis/redis-py · error · ValueError
Cannot enable maintenance notifications for connection…
Error message
Cannot enable maintenance notifications for connection object that doesn't have a host attribute.
What it means
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.
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
Defensive patterns
Strategy: validation
Validate before calling
if getattr(conn, 'host', None) is None:
raise ValueError('connection has no host; cannot enable maintenance notifications') Prevention
- Only enable maintenance notifications on connections that carry a host
- Use the standard connection classes in production paths
When it happens
Trigger: 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.
Common situations: Testing with mock connections; custom connection subclasses used in multidb/failover paths.
Related errors
- To configure maintenance notifications, a parser must be…
- Maintenance notifications are only supported with hiredis…
- The server doesn't support maintenance notifications
- To configure maintenance notifications, a parser must be…
- Bad response from PING health check
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/55c04028f08ba389.
Report an issue: GitHub.
Appendix: source
Thrown at redis/asyncio/connection.py:401
and self.maint_notifications_config
and self.maint_notifications_config.enabled
and self._maint_notifications_connection_handler
and host is not None
):
await self._enable_maintenance_notifications(
maint_notifications_config=self.maint_notifications_config,
check_health=check_health,
)
async def _enable_maintenance_notifications(
self,
maint_notifications_config: MaintNotificationsConfig,
check_health: bool = True,
) -> None:
try:
host = getattr(self, "host", None)
if host is None:
raise ValueError(
"Cannot enable maintenance notifications for connection"
" object that doesn't have a host attribute."
)
endpoint_type = maint_notifications_config.get_endpoint_type(host, self)
await self.send_command(
"CLIENT",
"MAINT_NOTIFICATIONS",
"ON",
"moving-endpoint-type",
endpoint_type.value,
check_health=check_health,
)
response = await self.read_response()
if not response or str_if_bytes(response) != "OK":
raise ResponseError(
"The server doesn't support maintenance notifications"
)View on GitHub (pinned to 6a6b581b48)