diff --git a/persistence/sql/identity/persister_identity.go b/persistence/sql/identity/persister_identity.go index afa525184f03..7649f6aca3bd 100644 --- a/persistence/sql/identity/persister_identity.go +++ b/persistence/sql/identity/persister_identity.go @@ -584,7 +584,7 @@ func (p *IdentityPersister) CreateIdentities(ctx context.Context, identities ... } } - if err := p.Transaction(ctx, func(ctx context.Context, tx *pop.Connection) error { + return p.Transaction(ctx, func(ctx context.Context, tx *pop.Connection) error { conn := &batch.TracerConnection{ Tracer: p.r.Tracer(ctx), Connection: tx, @@ -645,10 +645,14 @@ func (p *IdentityPersister) CreateIdentities(ctx context.Context, identities ... if len(failedIdentityIDs) > 0 { partialErr := &identity.CreateIdentitiesError{} failedIDs := make([]uuid.UUID, 0, len(failedIdentityIDs)) + succeededIDs := make([]uuid.UUID, 0, len(identities)) + for _, ident := range identities { if _, ok := failedIdentityIDs[ident.ID]; ok { partialErr.AddFailedIdentity(ident, sqlcon.ErrUniqueViolation) failedIDs = append(failedIDs, ident.ID) + } else { + succeededIDs = append(succeededIDs, ident.ID) } } // Manually roll back by deleting the identities that were inserted before the @@ -656,21 +660,22 @@ func (p *IdentityPersister) CreateIdentities(ctx context.Context, identities ... if err := p.DeleteIdentities(ctx, failedIDs); err != nil { return sqlcon.HandleError(err) } - // Wrap the partial error with the first error that occurred, so that the caller - // can continue to handle the error either as a partial error or a full error. + + // Partial success: report succeeded identities as created. + for _, identID := range succeededIDs { + span.AddEvent(events.NewIdentityCreated(ctx, identID)) + } + return partialErr + } else { + // No failures: report all identities as created. + for _, ident := range identities { + span.AddEvent(events.NewIdentityCreated(ctx, ident.ID)) + } } return nil - }); err != nil { - return err - } - - for _, ident := range identities { - span.AddEvent(events.NewIdentityCreated(ctx, ident.ID)) - } - - return nil + }) } func (p *IdentityPersister) HydrateIdentityAssociations(ctx context.Context, i *identity.Identity, expand identity.Expandables) (err error) {