{"record":{"id":"fbc54afd59a11131","repo":"MemPalace/mempalace","slug":"collection-name-fbc54a","errorCode":null,"errorMessage":"{collection_name}","messagePattern":"\\{collection_name\\}","errorType":"exception","errorClass":"CollectionNotInitializedError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/sqlite_exact.py","lineNumber":322,"sourceCode":"            self._ensure_open()\n            cur = self._handle.conn.cursor()\n            try:\n                yield cur\n            except Exception:\n                self._handle.conn.rollback()\n                raise\n            else:\n                self._handle.conn.commit()\n            finally:\n                cur.close()\n\n    def _collection_id(self, cur) -> int:\n        row = cur.execute(\n            \"SELECT id FROM collections WHERE name = ?\",\n            (self._collection_name,),\n        ).fetchone()\n        if row is None:\n            raise CollectionNotInitializedError(self._collection_name)\n        return int(row[0])\n\n    def _collection_dimension(self, cur, collection_id: int) -> Optional[int]:\n        row = cur.execute(\n            \"SELECT dimension FROM collections WHERE id = ?\",\n            (collection_id,),\n        ).fetchone()\n        if row is None or row[0] is None:\n            return None\n        return int(row[0])\n\n    def _ensure_collection_dimension(self, cur, collection_id: int, dims: list[int]) -> None:\n        distinct = {int(dim) for dim in dims}\n        if not distinct:\n            return\n        if len(distinct) > 1:\n            raise DimensionMismatchError(\n                f\"sqlite_exact collection {self._collection_name!r} cannot mix \"","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/sqlite_exact.py#L304-L340","documentation":"`CollectionNotInitializedError` carrying just the collection name, raised from `SQLiteExactCollection._collection_id`. It means the collection row is missing from the `collections` table even though a collection object exists — the handle connected fine, but the name was never created (or was deleted) in this database file.","triggerScenarios":"Using a collection handle obtained with `create=True` from one palace path against a different/empty db (path confusion); the collection was deleted by `delete_collection` while a stale handle is still used; the db file was replaced/restored from backup after the handle was created; concurrent creation raced and the row rolled back.","commonSituations":"Switching PALACE_PATH or working directory between get_collection and later operations; tests sharing module-scoped handles against per-test fresh dbs; restoring a palace from a snapshot while the process holds old collection objects.","solutions":["Re-obtain the collection with `create=True` after the underlying db changes: `col = backend.get_collection(palace, name, create=True)`.","Verify you are pointing at the same palace path that the handle was created from (print both paths).","Do not reuse collection handles after `delete_collection`; fetch a fresh one.","If a writer crashed mid-create, the transaction rolled back — simply call get_collection(create=True) again."],"exampleFix":"# before\ncol = backend.get_collection(palace, \"drawers\")  # create=False, row missing\ncol.count()\n\n# after\ncol = backend.get_collection(palace, \"drawers\", create=True)\ncol.count()","handlingStrategy":"try-catch","validationCode":"def collection_exists(backend, palace, name) -> bool:\n    try:\n        backend.get_collection(palace, name)\n        return True\n    except CollectionNotInitializedError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    col.count()\nexcept CollectionNotInitializedError:\n    col = backend.get_collection(palace, col._collection_name, create=True)\n    col.count()","preventionTips":["Fetch collection handles freshly per task instead of storing them long-term.","Log the palace path alongside collection operations to catch path-switch bugs.","After restore/backup operations, drop all cached handles and reopen."],"tags":["sqlite-exact","collection","lifecycle","not-initialized"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}