fix(region): check instance snapshot joint is nil on snapshot purge (#24515)

This commit is contained in:
wanyaoqi
2026-03-22 23:59:39 +08:00
committed by GitHub
parent 1ec3a231b3
commit 2fa1606e7c

View File

@@ -635,10 +635,16 @@ func (self *SInstanceSnapshot) PerformPurge(ctx context.Context, userCred mcclie
isjp := new(SInstanceSnapshotJoint)
err = InstanceSnapshotJointManager.Query().
Equals("instance_snapshot_id", self.Id).Equals("snapshot_id", snapshotId).First(isjp)
err = isjp.Delete(ctx, userCred)
if err != nil {
return nil, errors.Wrapf(err, "delete instance snapshot joint: %s", snapshotId)
if err == nil || isjp != nil {
isjp.SetModelManager(InstanceSnapshotJointManager, isjp)
err = isjp.Delete(ctx, userCred)
if err != nil {
return nil, errors.Wrapf(err, "delete instance snapshot joint: %s", snapshotId)
}
} else {
log.Errorf("failed get instance_snapshot %s join %s: %s", self.Id, snapshotId, err)
}
_, err = snapshots[i].PerformPurge(ctx, userCred, query, data)
if err != nil {
return nil, errors.Wrapf(err, "delete snapshot: %s", snapshotId)