redis/redis-py · error · ValueError
Given database is not a member of database list
Error message
Given database is not a member of database list
What it means
Raised as ValueError by MultiDBClient.set_active_database() (client.py:151) when the supplied Database object is not found in self._databases. Promotion to active requires the database to already be a registered member of the client's weighted database list; an unknown object is rejected before any health check runs.
Source
Thrown at redis/multidb/client.py:151
def get_databases(self) -> Databases:
"""
Returns a sorted (by weight) list of all databases.
"""
return self._databases
def set_active_database(self, database: SyncDatabase) -> None:
"""
Promote one of the existing databases to become an active.
"""
exists = None
for existing_db, _ in self._databases:
if existing_db == database:
exists = True
break
if not exists:
raise ValueError("Given database is not a member of database list")
self._bg_scheduler.run_coro_sync(self._check_db_health, database)
if database.circuit.state == CBState.CLOSED:
highest_weighted_db, _ = self._databases.get_top_n(1)[0]
self.command_executor.active_database = (
database,
GeoFailoverReason.MANUAL,
)
return
raise NoValidDatabaseException(
"Cannot set active database, database is unhealthy"
)
def add_database(
self, config: DatabaseConfig, skip_initial_health_check: bool = True
):View on GitHub (pinned to 6a6b581b48)
Solutions
- Only pass Database instances returned by client.get_databases() to set_active_database().
- If the target isn't registered, add it first via client.add_database(config).
- Resolve the desired database from get_databases() by matching its identity field rather than reconstructing it.
Example fix
# before new_db = Database(client=other_client, circuit=..., weight=1) client.set_active_database(new_db) # raises ValueError # after client.add_database(db_config) # register it first target = next(db for db, _ in client.get_databases() if db is desired) client.set_active_database(target)
Defensive patterns
Strategy: validation
Validate before calling
# Validate membership before promoting
registered = [db for db, _ in client.get_databases()]
if database not in registered:
raise ValueError('database is not registered with this client')
client.set_active_database(database) Type guard
from redis.multidb.client import MultiDBClient
def is_registered(client: MultiDBClient, database) -> bool:
return any(db is database for db, _ in client.get_databases()) Try / catch
try:
client.set_active_database(database)
except ValueError as e:
if 'not a member' in str(e):
# register first, then promote
client.add_database(config_for(database))
client.set_active_database(database)
else:
raise Prevention
- Always obtain Database handles from get_databases(), never reconstruct them.
- Do not reuse Database objects across different MultiDBClient instances.
- Check membership before manual promotion.
When it happens
Trigger: Passing a freshly constructed Database (not added via add_database()) to set_active_database(); passing a Database belonging to a different MultiDBClient instance; passing an object that fails equality against the registered entries (Database.__eq__ compares underlying fields).
Common situations: Calling set_active_database with a Database reference obtained outside the client; swapping client instances and reusing old Database handles; mutating fields that affect equality after registration.
Related errors
- Given database is not a member of database list
- Cannot set active database, database is unhealthy
- HIMPORT is not supported on the multi-database (Active-Activ
- PubSub is not supported for RedisCluster
- Cluster client has no nodes - cannot create health check cli
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/5cddfc776aeb26db.
Report an issue: GitHub.