diff --git a/server/datastore/mysql/hosts.go b/server/datastore/mysql/hosts.go index df82354692..44f73728a2 100644 --- a/server/datastore/mysql/hosts.go +++ b/server/datastore/mysql/hosts.go @@ -2862,14 +2862,14 @@ func (ds *Datastore) ReplaceHostDeviceMapping(ctx context.Context, hid uint, map insPart = ` (?, ?, ?),` ) - // index the mappings by email and source, to quickly check which ones - // need to be deleted and inserted - toIns := make(map[string]*fleet.HostDeviceMapping) - for _, m := range mappings { - toIns[m.Email+"\n"+m.Source] = m - } - return ds.withRetryTxx(ctx, func(tx sqlx.ExtContext) error { + // index the mappings by email and source, to quickly check which ones + // need to be deleted and inserted + toIns := make(map[string]*fleet.HostDeviceMapping) + for _, m := range mappings { + toIns[m.Email+"\n"+m.Source] = m + } + var prevMappings []*fleet.HostDeviceMapping if err := sqlx.SelectContext(ctx, tx, &prevMappings, selStmt, hid); err != nil { return ctxerr.Wrap(ctx, err, "select previous host emails")