DjangoGirls / djangogirls

Website for DjangoGirls.org
http://djangogirls.org/
BSD 3-Clause "New" or "Revised" License
465 stars 286 forks source link

HttpError: <HttpError 404 when requesting https://admin.googleapis.com/admin/directory/v1/users/aba-5%40djan... #891

Closed sentry-io[bot] closed 8 months ago

sentry-io[bot] commented 1 year ago

Sentry Issue: DJANGO-GIRLS-WEBSITE-5C

HttpError: <HttpError 404 when requesting https://admin.googleapis.com/admin/directory/v1/users/aba-5%40djangogirls.org?alt=json returned "Resource Not Found: userKey". Details: "[{'message': 'Resource Not Found: userKey', 'domain': 'global', 'reason': 'notFound'}]">
(6 additional frame(s) were not displayed)
...
  File "organize/admin.py", line 177, in view_change_application_status
    application.send_deployed_email(event)
  File "organize/models.py", line 217, in send_deployed_email
    dummy_email, email_password = gmail_accounts.get_or_create_gmail(event_application=self, event=event)
  File "core/gmail_accounts.py", line 131, in get_or_create_gmail
    migrate_gmail_account(event, event_application.website_slug)
  File "core/gmail_accounts.py", line 94, in migrate_gmail_account
    ).execute()
mdehsan873 commented 1 year ago

@amakarudze Hi could you please explain the bug how to reproduce it and what should be the desired output So i can work on this bug? Thank you.

amakarudze commented 8 months ago

Sorry @mdehsan873 for taking so long to respond to you. Let me try and explain the issue happening here:

The concept is when we have a new event, we create a new @djangogirls.org email address for the event. This is covered by create_gmail_account(event) here. When an event has already happened in that city, one of these two scenarios can be true:

  1. The same organisers or at least one member of the past organisers is organising the new event. In that case, nothing should happen as the email address already exists and the team can get access through the old team.
  2. All members of the organising team for the new event are new. In this case, we want to rename the old email and create a new email address for the new team. This is handled by migrate_gmail_account(new_event, slug) here

I have checked the error logs and noticed there are two breakpoints for the migrate_gmail_account(new_event, slug) function. The first one is when trying to rename the old account here, the email is not found or doesn't exist. I have manually checked for the emails that had failed to be migrated by searching for them in the Google Admin console and I didn't find them as well. This gives a 404 error. We get the old email through the make_email(slug) function here.

PATCH https://admin.googleapis.com/admin/directory/v1/users/loja-3%40djangogirls.org [404]

The second instance is after renaming the account, the account will have become an alias and we don't want the alias so we try to delete the account here. The alias again is not found and gives the 404 error.

My thinking is we need to handle two things:

  1. Fix the email migration so it works well. The error is happening due to the slug being changed when a newer event is deployed. The number added to the slug is causing the error so using regex to remove the -3 to the slug should fix this.
  2. Add error handling so that failure does not result in a server error.

Reproducing this may be too complex as it requires a service account with access to our domain. I have just started looking at this, so maybe we can share thoughts.