@@ -111,19 +111,23 @@ func (s AGPLIDPSync) SyncOrganizations(ctx context.Context, tx database.Store, u
111
111
return org .ID
112
112
})
113
113
114
- expectedOrganizations ,err := tx .GetOrganizations (ctx , database.GetOrganizationsParams {
115
- IDs :expectedOrgIDs ,
116
- // Do not include deleted organizations
117
- Deleted :false ,
118
- })
119
- if err != nil {
120
- return xerrors .Errorf ("failed to get expected organizations: %w" ,err )
114
+ // finalExpected is the final set of org ids the user is expected to be in.
115
+ // Deleted orgs are omitted from this set.
116
+ finalExpected := expectedOrgIDs
117
+ if len (expectedOrgIDs )> 0 {
118
+ expectedOrganizations ,err := tx .GetOrganizations (ctx , database.GetOrganizationsParams {
119
+ IDs :expectedOrgIDs ,
120
+ // Do not include deleted organizations
121
+ Deleted :false ,
122
+ })
123
+ if err != nil {
124
+ return xerrors .Errorf ("failed to get expected organizations: %w" ,err )
125
+ }
126
+ finalExpected = db2sdk .List (expectedOrganizations ,func (org database.Organization ) uuid.UUID {
127
+ return org .ID
128
+ })
121
129
}
122
130
123
- finalExpected := db2sdk .List (expectedOrganizations ,func (org database.Organization ) uuid.UUID {
124
- return org .ID
125
- })
126
-
127
131
// Find the difference in the expected and the existing orgs, and
128
132
// correct the set of orgs the user is a member of.
129
133
add ,remove := slice .SymmetricDifference (existingOrgIDs ,finalExpected )
@@ -142,7 +146,7 @@ func (s AGPLIDPSync) SyncOrganizations(ctx context.Context, tx database.Store, u
142
146
})
143
147
if err != nil {
144
148
if xerrors .Is (err ,sql .ErrNoRows ) {
145
- // This should not happen because we check the orgexistance
149
+ // This should not happen because we check the orgexistence
146
150
// beforehand.
147
151
notExists = append (notExists ,orgID )
148
152
continue