diff --git a/pkg/compute/models/purge.go b/pkg/compute/models/purge.go index 04520639aa..9559e89e56 100644 --- a/pkg/compute/models/purge.go +++ b/pkg/compute/models/purge.go @@ -630,9 +630,9 @@ func (snapshot *SSnapshot) purge(ctx context.Context, userCred mcclient.TokenCre lockman.LockObject(ctx, snapshot) defer lockman.ReleaseObject(ctx, snapshot) - err := snapshot.ValidateDeleteCondition(ctx) + err := snapshot.ValidatePurgeCondition(ctx) if err != nil { - return err + return errors.Wrapf(err, "ValidatePurgeCondition for snapshot %s(%s)", snapshot.Name, snapshot.Id) } return snapshot.RealDelete(ctx, userCred) } diff --git a/pkg/compute/models/snapshots.go b/pkg/compute/models/snapshots.go index 088aa22827..ddda9b41ea 100644 --- a/pkg/compute/models/snapshots.go +++ b/pkg/compute/models/snapshots.go @@ -621,6 +621,10 @@ func (self *SSnapshot) ValidateDeleteCondition(ctx context.Context) error { if self.Status == api.SNAPSHOT_DELETING { return httperrors.NewBadRequestError("Cannot delete snapshot in status %s", self.Status) } + return self.ValidatePurgeCondition(ctx) +} + +func (self *SSnapshot) ValidatePurgeCondition(ctx context.Context) error { count, err := InstanceSnapshotJointManager.Query().Equals("snapshot_id", self.Id).CountWithError() if err != nil { return httperrors.NewInternalServerError("Fetch instance snapshot error %s", err)