Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: handle deleted organizations in idp sync#17405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 13 commits intomainfromstevenmasley/org_idp_sync
Apr 16, 2025

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedApr 15, 2025
edited
Loading

Deleted organizations are still attempting to sync members. This causes an error on inserting the member, and would likely cause issues later in the sync process even if that member is inserted. Deleted orgs should be skipped.

The error that arises:

=== RUN   TestSyncOrganizations/OK    organizations_test.go:94:         Error Trace:/home/steven/go/src/github.com/coder/coder/coderd/idpsync/organizations_test.go:94        Error:      Received unexpected error:                    add user to organization:                        github.com/coder/coder/v2/coderd/idpsync.AGPLIDPSync.SyncOrganizations                            /home/steven/go/src/github.com/coder/coder/coderd/idpsync/organization.go:129                      - pq: duplicate key value violates unique constraint "organization_members_pkey"

@EmyrkEmyrk marked this pull request as ready for reviewApril 15, 2025 18:26
@EmyrkEmyrk requested a review fromaslilacApril 15, 2025 18:30
@EmyrkEmyrkforce-pushed thestevenmasley/org_idp_sync branch fromf1878af to9bdf31dCompareApril 15, 2025 18:31
Comment on lines +2360 to +2366
deleted := false
q.data.organizationMembers = slices.DeleteFunc(q.data.organizationMembers, func(member database.OrganizationMember) bool {
match := member.OrganizationID == arg.OrganizationID && member.UserID == arg.UserID
deleted = deleted || match
return match
})
iflen(deleted) == 0 {
if!deleted {
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

A dbmem bug I found

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

oh this is nasty, took me a minute to realize what the bug was. 💀

if you want, rather than trackdeleted yourself, you could do something like

newMembers:=slices.DeleteFunc(q.data.organizationMembers,func(member database.OrganizationMember)bool {returnmember.OrganizationID==arg.OrganizationID&&member.UserID==arg.UserID})iflen(newMembers)==len(q.data.organizationMembers) {returnsql.ErrNoRows}q.data.organizationMembers=newMembers

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I had thought about that as well. That felt a bit less direct and less intuitive to me though, so I went with the crude and simple lol

Comment on lines +58 to +64
-- Optionally provide a filter for deleted organizations.
CASE WHEN
sqlc.narg('deleted') :: boolean IS NULL THEN
true
ELSE
deleted = sqlc.narg('deleted')
END AND
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Adds the ability to query for all orgs, regardless of deletion

Deleted organizations are still attempting to sync members.This causes an error on inserting the member, and would likelycause issues later in the sync process even if that member isinserted. Deleted orgs should be skipped.
Idp sync should exclude deleted organizations and auto removemembers. They should not be members in the first place.
@EmyrkEmyrkforce-pushed thestevenmasley/org_idp_sync branch from7b0cb6c to909c895CompareApril 15, 2025 20:54
Comment on lines +118 to +120
// If you pass in an empty slice to the db arg, you get all orgs. So the slice
// has to be non-empty to get the expected set. Logically it also does not make
// sense to fetch an empty set from the db.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

yeah but this turns it into our problem. wouldn't this usually be the result of a configuration error?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't follow. You can configure it such that a user is in 0 orgs. Even if it's a configuration mistake on the admin, it is a valid configuration.

@EmyrkEmyrk merged commit669e790 intomainApr 16, 2025
29 checks passed
@stirby
Copy link
Collaborator

/cherry-pick release/2.20

gcp-cherry-pick-botbot pushed a commit that referenced this pull requestApr 16, 2025
…17405)Deleted organizations are still attempting to sync members. This causesan error on inserting the member, and would likely cause issues later inthe sync process even if that member is inserted. Deleted orgs should beskipped.
@matifali
Copy link
Member

/cherry-pick release/2.21

gcp-cherry-pick-botbot pushed a commit that referenced this pull requestApr 16, 2025
…17405)Deleted organizations are still attempting to sync members. This causesan error on inserting the member, and would likely cause issues later inthe sync process even if that member is inserted. Deleted orgs should beskipped.
@EmyrkEmyrk changed the titletest: add unit test to excercise bug when idp sync hits deleted orgschore: handle deleted organizations in idp syncApr 22, 2025
matifali pushed a commit that referenced this pull requestApr 22, 2025
…(cherry-pick#17405) (#17423)Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@aslilacaslilacaslilac approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@Emyrk@stirby@matifali@aslilac

[8]ページ先頭

©2009-2025 Movatter.jp