{"record":{"id":"37bb758d19308e61","repo":"lfnovo/open-notebook","slug":"failed-to-create-insight-no-id-in-result","errorCode":null,"errorMessage":"Failed to create insight - no ID in result","messagePattern":"Failed to create insight - no ID in result","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"commands/embedding_commands.py","lineNumber":456,"sourceCode":"            CREATE source_insight CONTENT {\n                \"source\": $source_id,\n                \"insight_type\": $insight_type,\n                \"content\": $content\n            };\n            \"\"\",\n            {\n                \"source_id\": ensure_record_id(input_data.source_id),\n                \"insight_type\": input_data.insight_type,\n                \"content\": input_data.content,\n            },\n        )\n\n        if not result or len(result) == 0:\n            raise ValueError(\"Failed to create insight - no result returned\")\n\n        insight_id = str(result[0].get(\"id\", \"\"))\n        if not insight_id:\n            raise ValueError(\"Failed to create insight - no ID in result\")\n\n        # 2. Submit embedding command (fire-and-forget)\n        submit_command(\n            \"open_notebook\",\n            \"embed_insight\",\n            {\"insight_id\": insight_id},\n        )\n        logger.debug(f\"Submitted embed_insight command for {insight_id}\")\n\n        processing_time = time.time() - start_time\n        logger.info(\n            f\"Successfully created insight {insight_id} for source \"\n            f\"{input_data.source_id} in {processing_time:.2f}s\"\n        )\n\n        return CreateInsightOutput(\n            success=True,\n            insight_id=insight_id,","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/commands/embedding_commands.py#L438-L474","documentation":"ValueError raised by create_insight_command when the insert result row exists but has no (or empty) 'id' field, so the command cannot obtain the new insight's ID to submit the follow-up embed_insight job. The str() conversion means even a missing key becomes '' and fails the check.","triggerScenarios":"SurrealDB returning a result object whose 'id' key is absent or null — e.g. a projection/RETURN clause that omits id, or a driver deserialization difference that nests the id elsewhere.","commonSituations":"SurrealDB or driver version changes altering the returned record shape; a repo_insert query modified to return projected fields without id.","solutions":["Inspect the actual insert result shape in worker logs / by reproducing the insert in SurrealDB","Pin or align the SurrealDB and surrealdb-driver versions with this project's requirements","Ensure the insert query's RETURN clause includes the full record (with id)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"result = await run_command('create_insight', payload)\nout = result.output\nif out.get('success'):\n    insight_id = out['result']['insight_id']\nelse:\n    insight_id = await fallback_create_insight_via_api(payload)  # e.g. POST /insights REST route","preventionTips":["Pin SurrealDB and driver versions to those this release tested against","Fall back to the REST insight-creation endpoint when the command path fails","Report result-shape regressions with the actual returned dict for diagnosis"],"tags":["python","valueerror","insight","surrealdb","missing-id"],"backgroundTag":"database-insert-no-result","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}