Skip to content

TypeError in OAuthCredentials.__str__ when some credentials have no token in the admin

Sentry Issue: ARKINDEX-BACKEND-WY

TypeError: 'NoneType' object is not subscriptable
(50 additional frame(s) were not displayed)
...
  File "django/forms/widgets.py", line 592, in optgroups
    for index, (option_value, option_label) in enumerate(self.choices):
  File "django/forms/models.py", line 1170, in __iter__
    yield self.choice(obj)
  File "django/forms/models.py", line 1184, in choice
    self.field.label_from_instance(obj),
  File "django/forms/models.py", line 1253, in label_from_instance
    return str(obj)
  File "arkindex/users/models.py", line 169, in __str__
  1. Go to Profile > OAuth
  2. Select Gitlab in the provider list
  3. Type in a invalid URL like https://eijsiofjseoifjsio in the URL field
  4. Try to authenticate
  5. Watch the browser get sad
  6. Open the Django admin, head over to the OAuth credentials list and find the credentials you just created
  7. Enjoy the HTTP 500

It seems any OAuthCredentials with a null token will cause this error, since __str__ relies on the token.

Edited by Erwan Rouchet