Skip to content

Switch session create to check oauth_github first, then get user#13856

Open
carols10cents wants to merge 2 commits into
rust-lang:mainfrom
carols10cents:user-oauth-github-switcheroo
Open

Switch session create to check oauth_github first, then get user#13856
carols10cents wants to merge 2 commits into
rust-lang:mainfrom
carols10cents:user-oauth-github-switcheroo

Conversation

@carols10cents
Copy link
Copy Markdown
Member

@carols10cents carols10cents commented Jun 4, 2026

This is what I was talking about in this comment, that we can't use nice upserts but need to do multiple update/select/inserts in a transaction instead, so that we switch to using oauth_github as the source of truth of whether we're logging in an existing user or a new user.

I've extracted this from #13832 and I think making this change first is needed before we can stop using users.{gh_id, gh_avatar, gh_encrypted_token}.

We have `new_user`, which is a crates.io `NewUser`. I'm about to add usage
of crates.io `User`s, which I think will be confusing unless this
varibale name changes.
.set((
users::name.eq(gh_user.name.as_ref()),
users::gh_login.eq(&gh_user.login),
// users::username.eq(&gh_user.login),
Copy link
Copy Markdown
Member Author

@carols10cents carols10cents Jun 4, 2026

Choose a reason for hiding this comment

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

This will need to be uncommented if #13781 gets in first

View changes since the review

.build();

let user_id =
create_or_update_user(&new_user, gh_user.email.as_deref(), emails, conn)
Copy link
Copy Markdown
Member Author

@carols10cents carols10cents Jun 4, 2026

Choose a reason for hiding this comment

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

create_or_update_user really should only be creating, i think. And it starts its own transaction, but i don't think diesel/postgres cares about nested transactions.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

but i don't think diesel/postgres cares about nested transactions

it does:

If there is already an open transaction, savepoints will be used instead.

(from https://docs.diesel.rs/1.4.x/diesel/connection/trait.Connection.html#method.transaction)

@carols10cents carols10cents marked this pull request as ready for review June 4, 2026 19:45
@carols10cents carols10cents changed the title WIP: Switch session create to check oauth_github first, then get user Switch session create to check oauth_github first, then get user Jun 4, 2026
Comment on lines +283 to +287
Err(error) if is_read_only_error(&error) => {
// If we're in read only mode, we can't update their details
// just look for an existing user
find_user_by_gh_id(conn, gh_user.id).await?.ok_or(error)
}
Copy link
Copy Markdown
Member

@Turbo87 Turbo87 Jun 5, 2026

Choose a reason for hiding this comment

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

this change has a hidden regression that becomes visible with #13862.

previously the nested transactions caused the "read-only error -> use read-only query instead" case to work, but now the transaction is poisoned and won't work anymore for the read-only query either.

and in case you think I'm clever: nope, this was found by Claude 😅

View changes since the review

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 5, 2026

☔ The latest upstream changes (possibly #13781) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants