From 33ceb0ab9fb59f77b167962f2563287906af40df Mon Sep 17 00:00:00 2001 From: Lucas Manuel Rodriguez Date: Tue, 5 Dec 2023 18:25:11 -0300 Subject: [PATCH] Update edge case bug in `ds.UpdateHostDeviceMapping` (#15454) Found by @mna while working on #14779. Sort of an edge case but the change is simple enough to fix it. --- server/datastore/mysql/hosts.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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")