{"record":{"id":"4a1509465ff4f04b","repo":"lfnovo/open-notebook","slug":"table-name-with-id-id-not-found","errorCode":null,"errorMessage":"{table_name} with id {id} not found","messagePattern":"(.+?) with id (.+?) not found","errorType":"exception","errorClass":"NotFoundError","httpStatus":404,"severity":"warning","filePath":"open_notebook/domain/base.py","lineNumber":126,"sourceCode":"        try:\n            # Get the table name from the ID (everything before the first colon)\n            table_name = id.split(\":\")[0] if \":\" in id else id\n\n            # If we're calling from a specific subclass and IDs match, use that class\n            if cls.table_name and cls.table_name == table_name:\n                target_class: Type[T] = cls\n            else:\n                # Otherwise, find the appropriate subclass based on table_name\n                found_class = cls._get_class_by_table_name(table_name)\n                if not found_class:\n                    raise InvalidInputError(f\"No class found for table {table_name}\")\n                target_class = cast(Type[T], found_class)\n\n            result = await repo_query(\"SELECT * FROM $id\", {\"id\": ensure_record_id(id)})\n            if result:\n                return target_class(**result[0])\n            else:\n                raise NotFoundError(f\"{table_name} with id {id} not found\")\n        except Exception as e:\n            logger.error(f\"Error fetching object with id {id}: {str(e)}\")\n            logger.exception(e)\n            raise NotFoundError(f\"Object with id {id} not found - {str(e)}\")\n\n    @classmethod\n    def _get_class_by_table_name(cls, table_name: str) -> Optional[Type[\"ObjectModel\"]]:\n        \"\"\"Find the appropriate subclass based on table_name.\"\"\"\n\n        def get_all_subclasses(c: Type[\"ObjectModel\"]) -> List[Type[\"ObjectModel\"]]:\n            all_subclasses: List[Type[\"ObjectModel\"]] = []\n            for subclass in c.__subclasses__():\n                all_subclasses.append(subclass)\n                all_subclasses.extend(get_all_subclasses(subclass))\n            return all_subclasses\n\n        for subclass in get_all_subclasses(ObjectModel):\n            if hasattr(subclass, \"table_name\") and subclass.table_name == table_name:","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/open_notebook/domain/base.py#L108-L144","documentation":"get(id) executed the query successfully but SurrealDB returned no row for the given record id, so there is nothing to deserialize and NotFoundError is raised. This is the normal 'record does not exist' signal, not an infrastructure failure.","triggerScenarios":"await Note.get('note:abc') where that record was deleted or never existed; race where another process deleted the row between listing and get; id copied with a wrong/typo'd key portion.","commonSituations":"Stale ids cached in the frontend or embedded in notebook cells/queues after the source was deleted; user follows an old link; concurrent cleanup jobs.","solutions":["Catch NotFoundError and surface a 404 to the user","If the id came from a cached list, refresh the list / purge stale ids","Verify the id by listing records in that table first when debugging"],"exampleFix":"# before\nnote = await Note.get(note_id)  # unhandled NotFoundError\n\n# after\nfrom open_notebook.domain.errors import NotFoundError\ntry:\n    note = await Note.get(note_id)\nexcept NotFoundError:\n    raise HTTPException(status_code=404, detail=\"Note not found\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from open_notebook.domain.errors import NotFoundError\ntry:\n    note = await Note.get(note_id)\nexcept NotFoundError:\n    raise HTTPException(status_code=404, detail=\"Note not found\")","preventionTips":["Treat ids from caches/exports as potentially stale; re-validate before use","Catch NotFoundError at the API boundary and map to 404 instead of 500","Prefer listing fresh from the DB when building user-facing id lists"],"tags":["not-found","record-id","open-notebook","surrealdb"],"backgroundTag":"record-not-found","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}