Skip to content

Commit

Permalink
Log when duplicate external IDs are encountered (#152)
Browse files Browse the repository at this point in the history
External IDs have to be unique — currently if you provide an array of
models with identical external IDs, only the last one wins. To reduce
any confusion here, log a message that explains what's happening.
  • Loading branch information
samstarling authored Nov 25, 2024
1 parent 7daae0b commit d271162
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions reconcile/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,23 @@ func Entries(ctx context.Context, logger kitlog.Logger, cl EntriesClient, output
return errors.Wrap(err, "listing entries")
}

// Prepare a quick lookup of model by external ID, to power deletion.
modelsByExternalID := map[string]*output.CatalogEntryModel{}
// Prepare a quick lookup of model by external ID, to power deletion. We only need
// to store a boolean here, because we only care about the presence of a model by
// external ID.
modelsByExternalID := map[string]bool{}
for _, model := range entryModels {
modelsByExternalID[model.ExternalID] = model
// If we encounter two (or more) models with the same external ID, then we should
// log a warning. The external ID must be unique, so in the next phase we'll only
// create one catalog entry per external ID.
_, ok := modelsByExternalID[model.ExternalID]
if ok {
logger.Log(
"msg", "two entries with the same external ID provided, the first will be ignored",
"external_id", model.ExternalID,
)
}

modelsByExternalID[model.ExternalID] = true
}

{
Expand Down

0 comments on commit d271162

Please sign in to comment.