Skip to content

Handle team update scenario where GitHub team has been recreated #11653

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kailan
Copy link
Contributor

@kailan kailan commented Jul 28, 2025

If a team owns a crate, that team is deleted from GitHub, then recreated with the same name, a conflict would occur when adding the team to another crate because a team with the same login already exists but the github_id is different so it tries to insert a new team record instead.

This PR modifies the NewTeam::create_or_update function to attempt an update of the team record matching the (org_id, login) pair, allowing existing team records to be updated with new GitHub team IDs.

It also adds a test for the above described scenario.

Resolves #6949.

@kailan

This comment was marked as resolved.

@rustbot

This comment was marked as resolved.

@kailan

This comment was marked as resolved.

@rustbot rustbot added A-backend ⚙️ C-bug 🐞 Category: unintended, undesired behavior labels Jul 29, 2025
Copy link
Member

@Turbo87 Turbo87 left a comment

Choose a reason for hiding this comment

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

This seems like a good incremental improvement, thanks! 👍

For a bit more context: the way teams currently work is a bit problematic in various way. One is that they are somewhat tightly coupled to GitHub, which makes it hard(er) for us to support other identity providers. IMHO in the long term we should move team management into crates.io itself to avoid all of these issues, potentially with some functionality to sync GitHub team memberships with crates.io teams.

Copy link
Member

@Turbo87 Turbo87 left a comment

Choose a reason for hiding this comment

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

oops, forgot to submit my inline comment first... 😅

Comment on lines +141 to +158
let original_team = NewTeam::builder()
.login("github:test-org:core")
.org_id(1000)
.github_id(2001)
.build()
.create_or_update(&mut conn)
.await?;

let new_team = NewTeam::builder()
// same team name
.login(&original_team.login)
// same org ID
.org_id(original_team.org_id)
// different team ID
.github_id(original_team.github_id + 1)
.build()
.create_or_update(&mut conn)
.await?;
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit worried about these manual database mutations in the test, since they don't quite guarantee that the same logic is applied as it would through the API. I think the issue might be that this is mixing unit testing of the create_or_update() fn with integration testing of the API endpoint behavior.

I would suggest putting the unit test(s) into the database crate via mod tests and then adjusting the test here to only use the API endpoints. It might also make sense to use a custom GitHub API mock for this test so that we can better control the returned IDs.

We should probably also explicitly test the case where the org IDs do not match to avoid accidentally enabling resurrection attacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-bug 🐞 Category: unintended, undesired behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deleting and renaming a GitHub team gives it a new GitHub ID, which causes uniqueness constraint violations
3 participants