{"record":{"id":"7e0d09cc5a87fc13","repo":"AlistGo/alist","slug":"label-have-binding-relationships","errorCode":null,"errorMessage":"label have binding relationships","messagePattern":"label have binding relationships","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/op/label.go","lineNumber":16,"sourceCode":"package op\n\nimport (\n\t\"context\"\n\t\"github.com/alist-org/alist/v3/internal/db\"\n\t\"github.com/pkg/errors\"\n)\n\nfunc DeleteLabelById(ctx context.Context, id, userId uint) error {\n\t_, err := db.GetLabelById(id)\n\tif err != nil {\n\t\treturn errors.WithMessage(err, \"failed get label\")\n\t}\n\n\tif db.GetLabelFileBinDingByLabelIdExists(id, userId) {\n\t\treturn errors.New(\"label have binding relationships\")\n\t}\n\n\t// delete the label in the database\n\tif err := db.DeleteLabelById(id); err != nil {\n\t\treturn errors.WithMessage(err, \"failed delete label in database\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/internal/op/label.go#L1-L25","documentation":"DeleteLabelById refuses to delete a label that still has file-binding relationships for the user, checked via db.GetLabelFileBinDingByLabelIdExists(id, userId). Deleting would orphan those bindings, so the op requires the label to be unbound first. The label itself is confirmed to exist before this check.","triggerScenarios":"Calling op.DeleteLabelById(ctx, labelId, userId) while any file still carries that label (binding rows exist for that label id and user).","commonSituations":"Bulk-labeled files then attempting label cleanup; UI delete button hit without unbinding; shared labels across many objects.","solutions":["Remove the label from all files that use it, then retry the delete","Use the UI's bulk unbind feature if available before deleting the label","Check remaining bindings programmatically before offering delete in your own UI"],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// Before deleting a label\nif db.GetLabelFileBinDingByLabelIdExists(labelId, userId) {\n    return errors.New(\"unbind label from all files first\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Offer bulk-unbind in the UI before label deletion","Show binding counts next to labels so users see the constraint","Disable the delete button for bound labels"],"tags":["labels","delete","referential-integrity"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}