Skip to content
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

ActiveRecord::RecordNotUnique in omniauth_callbacks#openid_connect #13114

Open
mkllnk opened this issue Feb 3, 2025 · 3 comments · May be fixed by #13115
Open

ActiveRecord::RecordNotUnique in omniauth_callbacks#openid_connect #13114

mkllnk opened this issue Feb 3, 2025 · 3 comments · May be fixed by #13115
Assignees
Labels

Comments

@mkllnk
Copy link
Member

mkllnk commented Feb 3, 2025

ℹ️ Funded Feature. Please track ALL ASSOCIATED WORK under the associated tracking code #11678 DFC Orders

Error in OpenFoodNetwork UK

ActiveRecord::RecordNotUnique in omniauth_callbacks#openid_connect
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_oidc_accounts_on_uid"
DETAIL: Key (uid)=([email protected]) already exists.

View on Bugsnag

Stacktrace

app/models/oidc_account.rb:20 - link
app/controllers/omniauth_callbacks_controller.rb:5 - openid_connect

View full stacktrace

Created by David Cook via Bugsnag

@dacook
Copy link
Member

dacook commented Feb 3, 2025

This table has two unique indexes: uid and user_id. These are also validated by rails.
https://github.com/openfoodfoundation/openfoodnetwork/blob/master/db/schema.rb#L318-L319

But this upsert statement doesn't protect from a duplicate uid, hence the error. How did it happen, does it make sense and do we need to investigate further? I'm not sure but I think we need to understand it before choosing how to fix it.

@dacook
Copy link
Member

dacook commented Feb 3, 2025

It's as if Garethe tried to link his OFN account with a remote account that was already linked with another OFN account.
Oh, I guess he did:
Image

Simply user error? In that case, we should catch the exception and tell the user.

@dacook dacook self-assigned this Feb 3, 2025
@dacook dacook moved this from All the things 💤 to In Progress ⚙ in OFN Delivery board Feb 3, 2025
@dacook dacook linked a pull request Feb 3, 2025 that will close this issue
4 tasks
@mkllnk
Copy link
Member Author

mkllnk commented Feb 5, 2025

Yes, and if you are already logged into Keycloak and try to connect another OFN account then Keycloak doesn't prompt you to log in. I'm not sure what the best way to resolve this is. Should the user be guided to Keycloak to log out before trying again? Does Keycloak have a URL where you can choose the account even though you are logged into one already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress ⚙
Development

Successfully merging a pull request may close this issue.

2 participants