{"record":{"id":"2e15bebc33401e8e","repo":"goharbor/harbor","slug":"precondition-2e15be","errorCode":"PRECONDITION","errorMessage":"the registry %d is referenced by replication policies, cannot delete it","messagePattern":"the registry (.+?) is referenced by replication policies, cannot delete it","errorType":"http","errorClass":"lib/errors.Error","httpStatus":412,"severity":"error","filePath":"src/controller/registry/controller.go","lineNumber":142,"sourceCode":"func (c *controller) Update(ctx context.Context, registry *model.Registry, props ...string) error {\n\tif err := c.validate(ctx, registry); err != nil {\n\t\treturn err\n\t}\n\treturn c.regMgr.Update(ctx, registry, props...)\n}\n\nfunc (c *controller) Delete(ctx context.Context, id int64) error {\n\t// referenced by replication policy as source registry\n\tcount, err := c.repMgr.Count(ctx, &q.Query{\n\t\tKeywords: map[string]any{\n\t\t\t\"src_registry_id\": id,\n\t\t},\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\tif count > 0 {\n\t\treturn errors.New(nil).WithCode(errors.PreconditionCode).WithMessagef(\"the registry %d is referenced by replication policies, cannot delete it\", id)\n\t}\n\t// referenced by replication policy as destination registry\n\tcount, err = c.repMgr.Count(ctx, &q.Query{\n\t\tKeywords: map[string]any{\n\t\t\t\"dest_registry_id\": id,\n\t\t},\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\tif count > 0 {\n\t\treturn errors.New(nil).WithCode(errors.PreconditionCode).WithMessagef(\"the registry %d is referenced by replication policies, cannot delete it\", id)\n\t}\n\t// referenced by proxy cache project\n\tcount, err = c.proMgr.Count(ctx, &q.Query{\n\t\tKeywords: map[string]any{\n\t\t\t\"registry_id\": id,\n\t\t},","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/src/controller/registry/controller.go#L124-L160","documentation":"First referential check in registry Delete(): replication policies with src_registry_id = id are counted; a count > 0 refuses deletion with PRECONDITION 'the registry %d is referenced by replication policies, cannot delete it'. A registry used as a replication SOURCE cannot be removed while policies depend on it.","triggerScenarios":"DELETE /api/v2/registries/{id} while replication policies pull FROM this registry (it is their src_registry).","commonSituations":"Decommissioning an upstream registry without checking replication rules; shared registry retired while policies remain.","solutions":["List replication policies and delete or edit those with this registry as source (filter on src_registry_id).","Repeat the DELETE only when the count is zero.","Communicate with policy owners before removing shared source registries."],"exampleFix":"# before\nDELETE /api/v2/registries/5\n\n# after\nGET /api/v2/replication/policies?src_registry_id=5   # find dependents\nPUT  /api/v2/replication/policies/{pid}              # repoint src_registry or\nDELETE /api/v2/replication/policies/{pid}            # remove policy\nDELETE /api/v2/registries/5","handlingStrategy":"validation","validationCode":"// count source references before delete:\ncount, err := repMgr.Count(ctx, q.New(q.KeyWords{\"src_registry_id\": id}))\nif err != nil { return err }\nif count > 0 { return fmt.Errorf(\"%d replication policies use registry %d as source\", count, id) }\nreturn regCtl.Delete(ctx, id)","typeGuard":null,"tryCatchPattern":"if err := regCtl.Delete(ctx, id); err != nil {\n    if liberrors.IsErr(err, liberrors.PreconditionCode) {\n        // list policies (src_registry_id=id), delete or repoint, then retry\n    }\n    return err\n}","preventionTips":["Run a reference audit (src/dest/project) before decommissioning registries.","Keep IaC that owns replication policies and registries in one plan.","Retry the DELETE only after the dependent count is zero."],"tags":["registry","replication","precondition","delete","referential-integrity"],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}