{"record":{"id":"6ded6981e9493877","repo":"apache/cassandra","slug":"keyspace-r-not-found","errorCode":null,"errorMessage":"Keyspace %r not found.","messagePattern":"Keyspace %r not found\\.","errorType":"exception","errorClass":"KeyspaceNotFound","httpStatus":null,"severity":"error","filePath":"pylib/cqlshlib/cqlshmain.py","lineNumber":549,"sourceCode":"        return [f.name for f in list(self.get_keyspace_meta(ksname).functions.values())]\n\n    def get_useraggregate_names(self, ksname=None):\n        if ksname is None:\n            ksname = self.current_keyspace\n\n        return [f.name for f in list(self.get_keyspace_meta(ksname).aggregates.values())]\n\n    def get_cluster_name(self):\n        return self.conn.metadata.cluster_name\n\n    def get_partitioner(self):\n        return self.conn.metadata.partitioner\n\n    def get_keyspace_meta(self, ksname):\n        if ksname in self.conn.metadata.keyspaces:\n            return self.conn.metadata.keyspaces[ksname]\n\n        raise KeyspaceNotFound('Keyspace %r not found.' % ksname)\n\n    def get_keyspaces(self):\n        return list(self.conn.metadata.keyspaces.values())\n\n    def get_ring(self, ks):\n        self.conn.metadata.token_map.rebuild_keyspace(ks, build_if_absent=True)\n        return self.conn.metadata.token_map.tokens_to_hosts_by_ks[ks]\n\n    def get_table_meta(self, ksname, tablename):\n        if ksname is None:\n            ksname = self.current_keyspace\n        ksmeta = self.get_keyspace_meta(ksname)\n        if tablename not in ksmeta.tables:\n            if ksname == 'system_auth' and tablename in ['roles', 'role_permissions', 'generated_values']:\n                self.get_fake_auth_table_meta(ksname, tablename)\n            else:\n                raise ColumnFamilyNotFound(\"Column family {} not found\".format(tablename))\n        else:","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/pylib/cqlshlib/cqlshmain.py#L531-L567","documentation":"Shell.get_keyspace_meta resolves a keyspace name against conn.metadata.keyspaces. If the name is not present in the driver's keyspace metadata, it raises KeyspaceNotFound. Every schema lookup (tables, views, indexes, UDTs, functions) funnels through this method, so it is the root cause for most 'not found' errors in cqlsh.","triggerScenarios":"Any of get_columnfamily_names/get_materialized_view_names/get_index_names/get_usertype_names/get_usertype_layout/get_userfunction_names called with ksname that is absent from conn.metadata.keyspaces, or with current_keyspace set to a keyspace that no longer exists (e.g. after USE of a dropped keyspace or DROP KEYSPACE elsewhere).","commonSituations":"Typo in USE <keyspace>; another client dropped the keyspace while this session still points at it; schema disagreement in the cluster; connecting to the wrong cluster/environment (dev vs prod) where the keyspace doesn't exist.","solutions":["Run DESCRIBE KEYSPACES to list existing keyspaces and correct the name.","If the current keyspace was dropped, run USE <valid_keyspace> or clear the session keyspace before further lookups.","Refresh schema metadata (reconnect) if the keyspace was recently created and the driver metadata is stale.","Check cluster schema agreement (nodetool describecluster) if DDL was just applied."],"exampleFix":"// before\nshell.get_keyspace_meta('userks')  # KeyspaceNotFound (typo)\n// after\nshell.get_keyspace_meta('user_ks')  # correct keyspace name","handlingStrategy":"validation","validationCode":"if ksname not in shell.conn.metadata.keyspaces:\n    raise LookupError(f\"Keyspace {ksname!r} not in cluster metadata\")","typeGuard":"def keyspace_exists(shell, ksname):\n    return ksname in shell.conn.metadata.keyspaces","tryCatchPattern":"try:\n    meta = shell.get_keyspace_meta(ksname)\nexcept KeyspaceNotFound:\n    meta = None  # prompt user / refresh schema and retry once","preventionTips":["Run DESCRIBE KEYSPACES to confirm names before scripting against them.","USE an explicitly verified keyspace at session start.","Reconnect after DDL to avoid stale metadata.","Verify you are connected to the intended cluster/environment."],"tags":["cassandra","cqlsh","keyspace","schema-metadata","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}