{"record":{"id":"2e68ab728fc8dcc5","repo":"infiniflow/ragflow","slug":"database-error-list-by-parent-id","errorCode":null,"errorMessage":"Database error (list_by_parent_id)!","messagePattern":"Database error \\(list_by_parent_id\\)!","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"api/db/services/file_service.py","lineNumber":649,"sourceCode":"                }\n                DocumentService.insert(doc)\n\n                FileService.add_file_from_kb(doc, kb_folder[\"id\"], kb.tenant_id)\n                files.append((doc, blob))\n            except Exception as e:  # noqa: BLE001 - collect per-file errors and keep processing the rest\n                err.append(file.filename + \": \" + str(e))\n\n        return err, files\n\n    @classmethod\n    @DB.connection_context()\n    def list_all_files_by_parent_id(cls, parent_id):\n        try:\n            files = cls.model.select().where((cls.model.parent_id == parent_id) & (cls.model.id != parent_id))\n            return list(files)\n        except Exception:\n            logger.exception(\"list_by_parent_id failed\")\n            raise RuntimeError(\"Database error (list_by_parent_id)!\")\n\n    @staticmethod\n    def parse_docs(file_objs, user_id):\n        with ThreadPoolExecutor(max_workers=12) as exe:\n            threads = []\n            for file in file_objs:\n                threads.append(exe.submit(FileService.parse, file.filename, file.read(), False))\n\n            res = []\n            for th in threads:\n                res.append(th.result())\n\n        return \"\\n\\n\".join(res)\n\n    @staticmethod\n    def parse(filename, blob, img_base64=True, tenant_id=None, layout_recognize=None):\n        from api.apps import current_user\n        from rag.app import audio, email, naive, picture, presentation","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/api/db/services/file_service.py#L631-L667","documentation":"Raised by FileService.list_all_files_by_parent_id when the SELECT of children under a parent_id fails. The real exception is logged ('list_by_parent_id failed'); the RuntimeError is a generic wrapper for any DB-level failure during the query.","triggerScenarios":"Querying children of a folder while that subtree is being modified/deleted (lock contention), a dropped connection, or corrupted data causing the id != parent_id comparison to behave unexpectedly (e.g. NULL ids).","commonSituations":"Listing a folder during a large deletion or upload; database restart or failover mid-request; rare schema/data inconsistencies after manual edits.","solutions":["Check the server log for the wrapped exception to see the true cause.","Retry the listing after the concurrent write operation completes.","Verify DB connectivity and that the file table is intact (simple SELECT count(*) FROM file WHERE parent_id = ...).","If it recurs, examine rows for NULL or malformed id/parent_id values."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    files = FileService.list_all_files_by_parent_id(parent_id)\nexcept RuntimeError:\n    logger.warning('listing failed, likely contention; retrying')\n    files = FileService.list_all_files_by_parent_id(parent_id)","preventionTips":["Avoid listing a folder exactly while deleting or uploading into it.","Keep an eye on DB lock wait metrics if this recurs.","Use the returned error to trigger a UI refresh rather than showing raw errors."],"tags":["database","query","file-service","concurrency"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}