{"record":{"id":"5cd02bfa65da9dd8","repo":"langgenius/dify","slug":"dataset-collection-binding-not-found","errorCode":null,"errorMessage":"Dataset Collection Binding not found","messagePattern":"Dataset Collection Binding not found","errorType":"console","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"api/commands/vector.py","lineNumber":222,"sourceCode":"                if dataset.index_struct_dict:\n                    if dataset.index_struct_dict[\"type\"] == vector_type:\n                        skipped_count = skipped_count + 1\n                        continue\n                collection_name = \"\"\n                dataset_id = dataset.id\n                if vector_type in upper_collection_vector_types:\n                    collection_name = Dataset.gen_collection_name_by_id(dataset_id)\n                elif vector_type == VectorType.QDRANT:\n                    if dataset.collection_binding_id:\n                        dataset_collection_binding = db.session.execute(\n                            select(DatasetCollectionBinding).where(\n                                DatasetCollectionBinding.id == dataset.collection_binding_id\n                            )\n                        ).scalar_one_or_none()\n                        if dataset_collection_binding:\n                            collection_name = dataset_collection_binding.collection_name\n                        else:\n                            raise ValueError(\"Dataset Collection Binding not found\")\n                    else:\n                        collection_name = Dataset.gen_collection_name_by_id(dataset_id)\n\n                elif vector_type in lower_collection_vector_types:\n                    collection_name = Dataset.gen_collection_name_by_id(dataset_id).lower()\n                else:\n                    raise ValueError(f\"Vector store {vector_type} is not supported.\")\n\n                index_struct_dict = {\"type\": vector_type, \"vector_store\": {\"class_prefix\": collection_name}}\n                dataset.index_struct = json.dumps(index_struct_dict)\n                with Session(db.engine) as session:\n                    vector = Vector(dataset, session=session)\n                click.echo(f\"Migrating dataset {dataset.id}.\")\n\n                try:\n                    vector.delete()\n                    click.echo(\n                        click.style(f\"Deleted vector index {collection_name} for dataset {dataset.id}.\", fg=\"green\")","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/commands/vector.py#L204-L240","documentation":"ValueError raised during vector index creation when a Qdrant-backed dataset has a non-null collection_binding_id but the DatasetCollectionBinding row with that id does not exist in the database. The binding is required to derive the correct collection_name for Qdrant; its absence means the dataset points to a deleted binding.","triggerScenarios":"Triggered in the create-dataset-index migration loop when vector_type is QDRANT, dataset.collection_binding_id is set, and `select(DatasetCollectionBinding).where(id == collection_binding_id)` returns None.","commonSituations":"A DatasetCollectionBinding was deleted but the Dataset still references its id (orphaned FK), or the binding was never committed during a failed prior migration.","solutions":["Query `SELECT id, collection_binding_id FROM datasets WHERE id='<dataset_id>';` then check the binding row exists.","If orphaned, clear dataset.collection_binding_id so it falls back to gen_collection_name_by_id, or recreate the binding.","Skip the dataset and re-run after repair, since the loop continues on per-dataset exceptions.","Audit for other datasets referencing the missing binding."],"exampleFix":"-- before\n-- dataset.collection_binding_id='b1' but b1 row is gone -> raises\n\n-- after - either clear the dangling reference\nUPDATE datasets SET collection_binding_id=NULL WHERE id='<dataset_id>';\n-- or recreate the binding row with the correct collection_name","handlingStrategy":"validation","validationCode":"def binding_exists(session, binding_id: str | None) -> bool:\n    if not binding_id:\n        return True\n    return session.scalar(\n        select(func.count()).select_from(DatasetCollectionBinding)\n        .where(DatasetCollectionBinding.id == binding_id)\n    ) == 1","typeGuard":"def is_resolvable_binding(session, binding_id: str | None) -> bool:\n    if not binding_id:\n        return True\n    return session.scalar(select(DatasetCollectionBinding).where(DatasetCollectionBinding.id == binding_id)) is not None","tryCatchPattern":"try:\n    create_index_for_dataset(dataset)\nexcept ValueError as exc:\n    if \"Dataset Collection Binding not found\" in str(exc):\n        click.echo(f\"skip dataset={dataset.id} orphaned binding={dataset.collection_binding_id}\", err=True)\n        continue\n    raise","preventionTips":["Cascade-delete or null-out Dataset.collection_binding_id when a binding is removed.","Preflight datasets for dangling collection_binding_id before running the migration.","Skip and log orphaned datasets rather than aborting the whole run.","Add a foreign-key constraint or periodic integrity check."],"tags":["backend","cli","vector-store","qdrant","data-integrity","orphaned-reference"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}