Repository: mdn/kuma

Issue:
Viewing profile of user with Persona account generates an ISE
**Summary**
It seems that viewing the profile of a user who has a Persona social account triggers an ISE.

**Steps To Reproduce (STR)**
1. Visit https://developer.allizom.org/en-US/profiles/sheppy
2. It will generate a 500 error
3. Visit https://developer.allizom.org/en-US/profiles/escattone
4. Displays fine

**Actual behavior**
Returns 500 (internal server error)

**Expected behavior**
Success display of user's profile page

**Additional context**
This seems to be related to one or more of the account PR's that were merged prior to deploying to stage.



Discussion:
FYI, I know what this is and am working on a fix which I'll submit tomorrow morning.

Resolving patch:
diff --git a/kuma/users/templatetags/jinja_helpers.py b/kuma/users/templatetags/jinja_helpers.py
--- a/kuma/users/templatetags/jinja_helpers.py
+++ b/kuma/users/templatetags/jinja_helpers.py
@@ -18,11 +18,14 @@
 @library.global_function
 def get_avatar_url(user):
     """
-    Get the user's avatar URL for the first social account provider that has one.
-    Assumes that the user is not anonymous or None.
-    If the user has no avatar for any provider, returns the default avatar.
+    Get the avatar URL of the user's first-joined social account that has one,
+    excluding all Persona social accounts. Assumes that the user is not None or
+    anonymous. If the user has no social account with an avatar, returns the
+    default avatar URL.
     """
-    for account in user.socialaccount_set.order_by('date_joined'):
+    for account in (user.socialaccount_set
+                        .exclude(provider='persona')
+                        .order_by('date_joined')):
         avatar_url = account.get_avatar_url()
         if avatar_url:
             return avatar_url


Test patch:
diff --git a/kuma/users/tests/test_helpers.py b/kuma/users/tests/test_helpers.py
--- a/kuma/users/tests/test_helpers.py
+++ b/kuma/users/tests/test_helpers.py
@@ -1,12 +1,45 @@
+import pytest
+from allauth.socialaccount.models import SocialAccount
 from django.conf import settings
 
 from ..templatetags.jinja_helpers import (get_avatar_url, is_username_taken,
                                           public_email)
 
 
-def test_get_avatar_url(wiki_user, wiki_user_github_account):
-    assert (get_avatar_url(wiki_user) ==
-            wiki_user_github_account.get_avatar_url())
+@pytest.mark.parametrize('providers', (
+    ('persona',),
+    ('persona', 'github', 'google'),
+    ('persona', 'google', 'github'),
+), ids=('default', 'github', 'google'))
+def test_get_avatar_url(wiki_user, providers):
+    SOCIAL_ACCOUNT_DATA = {
+        'github': {
+            'uid': 1234567,
+            'extra_data': {
+                'avatar_url': 'https://github/yada/yada',
+            }
+        },
+        'google': {
+            'uid': 123456789012345678901,
+            'extra_data': {
+                'picture': 'https://google/yada/yada'
+            }
+        },
+        'persona': {
+            'uid': wiki_user.email,
+        }
+    }
+    first_valid_avatar_url = None
+    for provider in providers:
+        sa = SocialAccount.objects.create(
+            user=wiki_user,
+            provider=provider,
+            **SOCIAL_ACCOUNT_DATA[provider]
+        )
+        if (not first_valid_avatar_url) and (provider != 'persona'):
+            first_valid_avatar_url = sa.get_avatar_url()
+    assert get_avatar_url(wiki_user) == (
+        first_valid_avatar_url or settings.DEFAULT_AVATAR)
 
 
 def test_get_avatar_url_default(wiki_user):