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

[API] UNIQUE constraint failed error #149

Open
Aksh-Bansal-dev opened this issue Jul 11, 2022 · 7 comments
Open

[API] UNIQUE constraint failed error #149

Aksh-Bansal-dev opened this issue Jul 11, 2022 · 7 comments
Labels
API to label task requiring changes in API bug Something isn't working

Comments

@Aksh-Bansal-dev
Copy link
Member

Steps to reproduce:

  • Start API server using docker
  • Click sign in on login page.
django.db.utils.IntegrityError: UNIQUE constraint failed: api_accounts_user.email
[11/Jul/2022 08:52:06] "POST /auth/token/ HTTP/1.1" 500 191429
@Samy-33 Samy-33 added bug Something isn't working API to label task requiring changes in API labels Jul 11, 2022
@arminpatel
Copy link
Member

arminpatel commented Jul 14, 2022

Tried to reproduce the bug, but my login was successful.

image

My best guess is that the email of superuser (or some manually added user) and the google email was same and hence result in breaking of uniqueness. Can someone else confirm?

@Samy-33
Copy link
Member

Samy-33 commented Jul 14, 2022

@Aksh-Bansal-dev, do you still face this issue? If yes, please do post the whole error that you get in the API console. It would probably a huge error message, you can paste it over: https://ctxt.io/ or some other pasting website online and share a link.

@Samy-33
Copy link
Member

Samy-33 commented Jul 14, 2022

My best guess is that the email of superuser (or some manually added user) and the google email was same and hence result in breaking of uniqueness. Can someone else confirm?

That's correct but it shouldn't happen, if the user is already present they should be logged in instead of throwing this error.
It's weird that you're not getting this error but @Aksh-Bansal-dev is. Let's wait for @Aksh-Bansal-dev to give us more info. If it was a transient error, we could close this and reopen again when we face it.

@Aksh-Bansal-dev
Copy link
Member Author

The ui sends 2 duplicate requests for the token, sometimes one of these requests returns 403.

Screenshot from 2022-07-14 23-15-43

@arminpatel
Copy link
Member

The ui sends 2 duplicate requests for the token, sometimes one of these requests returns 403.

Screenshot from 2022-07-14 23-15-43

Got the same error when I restarted the container.
image
{'email': '[email protected]', 'first_name': None, 'last_name': None, 'picture_url': None} is user_info from

user_info = self._extract_userdata_from_id_token(id_info)

@arminpatel
Copy link
Member

Got the orignally posted error: error log
My guess is that two requests are being sent simultaneously and for both of them the new user doesn't exist and both try to create a new one resulting in an integrity error (Race condition?).

@Samy-33
Copy link
Member

Samy-33 commented Jul 15, 2022

There are two possible solutions that I can think of right now:

  • Use throttling to allow 1 request per client per second
  • Handle django.db.utils.IntegrityError while creating a user.

There is one more issue though, sometimes it also throws 403 forbidden. Not sure why that's happening. We will wait and see if this causes more issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API to label task requiring changes in API bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants