From 36e038f5ffc2c986568a787c6f11d89482511205 Mon Sep 17 00:00:00 2001 From: Bryan Frimin Date: Thu, 30 Jul 2026 19:08:25 +0200 Subject: [PATCH] Join identities in MembershipProfiles.LoadExistingByIDs SCIM event CSV exports failed with "cannot parse address : mail: no address" because this query selected a placeholder empty string for email_address instead of the real address, and scanning it into mail.Addr tried to parse it as one. Join identities the same way every other MembershipProfile query already does, and drop the redundant identity lookup in the SCIM export path now that profiles carry their real email address. Signed-off-by: Bryan Frimin --- pkg/coredata/membership_profile.go | 4 +++- pkg/iam/log_export_csv.go | 17 +---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/pkg/coredata/membership_profile.go b/pkg/coredata/membership_profile.go index 5a5d392b1..e24d2e655 100644 --- a/pkg/coredata/membership_profile.go +++ b/pkg/coredata/membership_profile.go @@ -506,7 +506,7 @@ SELECT p.id, p.identity_id, p.organization_id, - ''::citext AS email_address, + i.email_address, p.source, p.state, p.full_name, @@ -541,6 +541,8 @@ SELECT p.updated_at FROM iam_membership_profiles p +INNER JOIN identities i + ON i.id = p.identity_id WHERE p.%s AND p.id = ANY(@profile_ids) diff --git a/pkg/iam/log_export_csv.go b/pkg/iam/log_export_csv.go index 9df1a124b..d0c1ec282 100644 --- a/pkg/iam/log_export_csv.go +++ b/pkg/iam/log_export_csv.go @@ -307,28 +307,13 @@ func loadSCIMProfileExportInfo( return scimProfileExportLookup{}, fmt.Errorf("cannot load SCIM export profiles: %w", err) } - identityIDs := make([]gid.GID, 0, len(profiles)) - for _, profile := range profiles { - identityIDs = append(identityIDs, profile.IdentityID) - } - - var identities coredata.Identities - if err := identities.LoadByIDs(ctx, conn, identityIDs); err != nil { - return scimProfileExportLookup{}, fmt.Errorf("cannot load SCIM profile identity emails: %w", err) - } - - emailByIdentityID := make(map[gid.GID]string, len(identities)) - for _, identity := range identities { - emailByIdentityID[identity.ID] = identity.EmailAddress.String() - } - lookup := scimProfileExportLookup{ byProfileID: make(map[gid.GID]scimProfileExportInfo, len(profiles)), byUserName: make(map[string]scimProfileExportInfo, len(profiles)), } for _, profile := range profiles { info := scimProfileExportInfo{ - email: emailByIdentityID[profile.IdentityID], + email: profile.EmailAddress.String(), fullName: profileFullName(profile), }