From 66b8e1830cb40a8bfc3b6a6e8757e12307bc98e9 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Tue, 24 Sep 2024 10:50:57 -0400 Subject: [PATCH] fix: don't fail if host profile not found --- server/datastore/mysql/apple_mdm.go | 4 ++++ server/service/apple_mdm.go | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/datastore/mysql/apple_mdm.go b/server/datastore/mysql/apple_mdm.go index f06f345a7d02..19bf4f9f8ee2 100644 --- a/server/datastore/mysql/apple_mdm.go +++ b/server/datastore/mysql/apple_mdm.go @@ -3935,6 +3935,10 @@ WHERE var hostProf fleet.HostMDMAppleProfile if err := sqlx.GetContext(ctx, ds.writer(ctx), &hostProf, stmt, uuid); err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, notFound("HostMDMAppleProfile") + } + return nil, ctxerr.Wrap(ctx, err, "getting host mdm apple profile by uuid") } diff --git a/server/service/apple_mdm.go b/server/service/apple_mdm.go index 772c85801307..7258abac9d44 100644 --- a/server/service/apple_mdm.go +++ b/server/service/apple_mdm.go @@ -772,14 +772,16 @@ func (svc *Service) DeleteMDMAppleConfigProfile(ctx context.Context, profileUUID hp, err := svc.ds.GetHostMDMAppleProfileByUUID(ctx, cp.ProfileUUID) if err != nil { - return ctxerr.Wrap(ctx, err, "getting host mdm apple profile") + if !fleet.IsNotFound(err) { + return ctxerr.Wrap(ctx, err, "getting host mdm apple profile") + } } if err := svc.ds.DeleteMDMAppleConfigProfile(ctx, profileUUID); err != nil { return ctxerr.Wrap(ctx, err) } - if hp.Status == nil && hp.OperationType == fleet.MDMOperationTypeInstall && hp.CommandUUID == "" { + if hp != nil && hp.Status == nil && hp.OperationType == fleet.MDMOperationTypeInstall && hp.CommandUUID == "" { if err := svc.ds.DeleteHostMDMAppleProfileByUUID(ctx, cp.ProfileUUID); err != nil { return ctxerr.Wrap(ctx, err, "deleting host mdm apple profile") }