diff --git a/server/datastore/mysql/apple_mdm.go b/server/datastore/mysql/apple_mdm.go index a88faa41ed..054f07add5 100644 --- a/server/datastore/mysql/apple_mdm.go +++ b/server/datastore/mysql/apple_mdm.go @@ -1266,7 +1266,7 @@ WHERE hmap.checksum as checksum, hmap.status as status, hmap.operation_type as operation_type, - hmap.detail as detail, + COALESCE(hmap.detail, '') as detail, hmap.command_uuid as command_uuid FROM ( SELECT @@ -1469,7 +1469,7 @@ func (ds *Datastore) ListMDMAppleProfilesToRemove(ctx context.Context) ([]*fleet hmap.host_uuid, hmap.checksum, hmap.operation_type, - hmap.detail, + COALESCE(hmap.detail, '') as detail, hmap.status, hmap.command_uuid FROM ( diff --git a/server/datastore/mysql/apple_mdm_test.go b/server/datastore/mysql/apple_mdm_test.go index 20946c31f8..e1e9e482ca 100644 --- a/server/datastore/mysql/apple_mdm_test.go +++ b/server/datastore/mysql/apple_mdm_test.go @@ -2885,6 +2885,15 @@ func testBulkSetPendingMDMAppleHostProfiles(t *testing.T, ds *Datastore) { linuxHost: {}, }) + // simulate an entry with some values set to NULL + ExecAdhocSQL(t, ds, func(q sqlx.ExtContext) error { + _, err := q.ExecContext(ctx, `UPDATE host_mdm_apple_profiles SET detail = NULL WHERE profile_id = ?`, globalProfiles[2].ProfileID) + if err != nil { + return err + } + return nil + }) + // do a final sync of all hosts, should not change anything err = ds.BulkSetPendingMDMAppleHostProfiles(ctx, hostIDsFromHosts(append(enrolledHosts, unenrolledHost, linuxHost)...), nil, nil, nil) require.NoError(t, err)