We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kuma/users/templatetags/jinja_helpers.py`
Content:
```
1 from allauth.account.utils import user_display
2 from allauth.socialaccount import providers
3 from allauth.socialaccount.templatetags.socialaccount import get_providers
4 from allauth.utils import get_request_param
5 from django.conf import settings
6 from django.contrib import admin
7 from django.utils.translation import ugettext
8 from django_jinja import library
9 from honeypot.templatetags.honeypot import render_honeypot_field
10 from jinja2 import contextfunction, escape, Markup
11 
12 from kuma.core.templatetags.jinja_helpers import datetimeformat
13 from kuma.core.urlresolvers import reverse
14 
15 from ..models import User
16 
17 
18 @library.global_function
19 def get_avatar_url(user):
20     """
21     Get the user's avatar URL for the first social account provider that has one.
22     Assumes that the user is not anonymous or None.
23     If the user has no avatar for any provider, returns the default avatar.
24     """
25     for account in user.socialaccount_set.order_by('date_joined'):
26         avatar_url = account.get_avatar_url()
27         if avatar_url:
28             return avatar_url
29     return settings.DEFAULT_AVATAR
30 
31 
32 @library.global_function
33 @contextfunction
34 def ban_links(context, ban_user, banner_user):
35     """Returns a link to ban a user"""
36     links = ''
37     if ban_user.id != banner_user.id and banner_user.has_perm('users.add_userban'):
38         active_ban = ban_user.active_ban
39         url_ban_cleanup = reverse('users.ban_user_and_cleanup',
40                                   kwargs={'username': ban_user.username})
41         if active_ban:
42             url = reverse('admin:users_userban_change', args=(active_ban.id,))
43             title = ugettext('Banned on %(ban_date)s by %(ban_admin)s.') % {
44                 'ban_date': datetimeformat(context, active_ban.date,
45                                            format='date', output='json'),
46                 'ban_admin': active_ban.by,
47             }
48             link = ('<a id="ban_link" href="%s" class="button ban-link" title="%s">%s'
49                     '<i aria-hidden="true" class="icon-ban"></i></a>'
50                     % (url, title, ugettext('Banned')))
51             link_cleanup = ('<a id="cleanup_link" href="%s" class="button negative ban-link">%s'
52                             '<i aria-hidden="true" class="icon-ban"></i></a>'
53                             % (url_ban_cleanup, ugettext('Clean Up Revisions')))
54         else:
55             url = reverse('users.ban_user', kwargs={'username': ban_user.username})
56             link = ('<a id="ban_link" href="%s" class="button negative ban-link">%s'
57                     '<i aria-hidden="true" class="icon-ban"></i></a>'
58                     % (url, ugettext('Ban User')))
59             link_cleanup = ('<a id="cleanup_link" href="%s" class="button negative ban-link">%s'
60                             '<i aria-hidden="true" class="icon-ban"></i></a>'
61                             % (url_ban_cleanup, ugettext('Ban User & Clean Up')))
62         links = link_cleanup + ' ' + link
63     return Markup(links)
64 
65 
66 @library.global_function
67 def admin_link(user):
68     """Returns a link to admin a user"""
69     url = reverse('admin:users_user_change', args=(user.id,),
70                   current_app=admin.site.name)
71     link = ('<a href="%s" class="button neutral">%s'
72             '<i aria-hidden="true" class="icon-wrench"></i></a>' %
73             (url, ugettext('Admin')))
74     return Markup(link)
75 
76 
77 @library.filter
78 def public_email(email):
79     """Email address -> publicly displayable email."""
80     return Markup('<span class="email">%s</span>' % unicode_to_html(email))
81 
82 
83 def unicode_to_html(text):
84     """Turns all unicode into html entities, e.g. &#69; -> E."""
85     return ''.join(['&#%s;' % ord(i) for i in text])
86 
87 
88 @library.global_function
89 def user_list(users):
90     """Turn a list of users into a list of links to their profiles."""
91     link = '<a href="%s">%s</a>'
92     list = ', '.join([link % (escape(u.get_absolute_url()), escape(u.username))
93                       for u in users])
94     return Markup(list)
95 
96 
97 # Returns a string representation of a user
98 library.global_function(user_display)
99 
100 # Returns a list of social authentication providers.
101 library.global_function(get_providers)
102 
103 
104 @library.global_function
105 @contextfunction
106 def provider_login_url(context, provider_id, **params):
107     """
108     {{ provider_login_url("github", next="/some/url") }}
109     """
110     request = context['request']
111     provider = providers.registry.by_id(provider_id)
112     auth_params = params.get('auth_params', None)
113     scope = params.get('scope', None)
114     process = params.get('process', None)
115     if scope == '':
116         del params['scope']
117     if auth_params == '':
118         del params['auth_params']
119     if 'next' not in params:
120         next = get_request_param(request, 'next')
121         if next:
122             params['next'] = next
123         elif process == 'redirect':
124             params['next'] = request.get_full_path()
125     else:
126         if not params['next']:
127             del params['next']
128     # get the login url and append params as url parameters
129     return Markup(provider.get_login_url(request, **params))
130 
131 
132 @library.global_function
133 @contextfunction
134 def providers_media_js(context):
135     """
136     {{ providers_media_js() }}
137     """
138     request = context['request']
139     return Markup('\n'.join([p.media_js(request)
140                              for p in providers.registry.get_list()]))
141 
142 
143 @library.global_function
144 def social_accounts(user):
145     """
146     {% set accounts = social_accounts(user) %}
147 
148     Then:
149         {{ accounts.twitter }} -- a list of connected Twitter accounts
150         {{ accounts.twitter.0 }} -- the first Twitter account
151         {% if accounts %} -- if there is at least one social account
152     """
153     accounts = {}
154     if not user.is_authenticated:
155         return accounts
156     for account in user.socialaccount_set.all().iterator():
157         providers = accounts.setdefault(account.provider, [])
158         providers.append(account)
159     return accounts
160 
161 
162 @library.global_function
163 @library.render_with('honeypot/honeypot_field.html')
164 def honeypot_field(field_name=None):
165     return render_honeypot_field(field_name)
166 
167 
168 @library.global_function
169 def get_primary_email(email_addresses):
170     for email in email_addresses:
171         if email_addresses[email].get('primary'):
172             return email
173 
174 
175 @library.global_function
176 def is_username_taken(username):
177     """
178     Returns True if a user with the given username exists (case-insentive),
179     otherwise False.
180     """
181     return User.objects.filter(username=username).exists()
182
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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

{"golden_diff": "diff --git a/kuma/users/templatetags/jinja_helpers.py b/kuma/users/templatetags/jinja_helpers.py\n--- a/kuma/users/templatetags/jinja_helpers.py\n+++ b/kuma/users/templatetags/jinja_helpers.py\n@@ -18,11 +18,14 @@\n @library.global_function\n def get_avatar_url(user):\n     \"\"\"\n-    Get the user's avatar URL for the first social account provider that has one.\n-    Assumes that the user is not anonymous or None.\n-    If the user has no avatar for any provider, returns the default avatar.\n+    Get the avatar URL of the user's first-joined social account that has one,\n+    excluding all Persona social accounts. Assumes that the user is not None or\n+    anonymous. If the user has no social account with an avatar, returns the\n+    default avatar URL.\n     \"\"\"\n-    for account in user.socialaccount_set.order_by('date_joined'):\n+    for account in (user.socialaccount_set\n+                        .exclude(provider='persona')\n+                        .order_by('date_joined')):\n         avatar_url = account.get_avatar_url()\n         if avatar_url:\n             return avatar_url\n", "issue": "Viewing profile of user with Persona account generates an ISE\n**Summary**\r\nIt seems that viewing the profile of a user who has a Persona social account triggers an ISE.\r\n\r\n**Steps To Reproduce (STR)**\r\n1. Visit https://developer.allizom.org/en-US/profiles/sheppy\r\n2. It will generate a 500 error\r\n3. Visit https://developer.allizom.org/en-US/profiles/escattone\r\n4. Displays fine\r\n\r\n**Actual behavior**\r\nReturns 500 (internal server error)\r\n\r\n**Expected behavior**\r\nSuccess display of user's profile page\r\n\r\n**Additional context**\r\nThis seems to be related to one or more of the account PR's that were merged prior to deploying to stage.\r\n\n", "before_files": [{"content": "from allauth.account.utils import user_display\nfrom allauth.socialaccount import providers\nfrom allauth.socialaccount.templatetags.socialaccount import get_providers\nfrom allauth.utils import get_request_param\nfrom django.conf import settings\nfrom django.contrib import admin\nfrom django.utils.translation import ugettext\nfrom django_jinja import library\nfrom honeypot.templatetags.honeypot import render_honeypot_field\nfrom jinja2 import contextfunction, escape, Markup\n\nfrom kuma.core.templatetags.jinja_helpers import datetimeformat\nfrom kuma.core.urlresolvers import reverse\n\nfrom ..models import User\n\n\n@library.global_function\ndef get_avatar_url(user):\n    \"\"\"\n    Get the user's avatar URL for the first social account provider that has one.\n    Assumes that the user is not anonymous or None.\n    If the user has no avatar for any provider, returns the default avatar.\n    \"\"\"\n    for account in user.socialaccount_set.order_by('date_joined'):\n        avatar_url = account.get_avatar_url()\n        if avatar_url:\n            return avatar_url\n    return settings.DEFAULT_AVATAR\n\n\n@library.global_function\n@contextfunction\ndef ban_links(context, ban_user, banner_user):\n    \"\"\"Returns a link to ban a user\"\"\"\n    links = ''\n    if ban_user.id != banner_user.id and banner_user.has_perm('users.add_userban'):\n        active_ban = ban_user.active_ban\n        url_ban_cleanup = reverse('users.ban_user_and_cleanup',\n                                  kwargs={'username': ban_user.username})\n        if active_ban:\n            url = reverse('admin:users_userban_change', args=(active_ban.id,))\n            title = ugettext('Banned on %(ban_date)s by %(ban_admin)s.') % {\n                'ban_date': datetimeformat(context, active_ban.date,\n                                           format='date', output='json'),\n                'ban_admin': active_ban.by,\n            }\n            link = ('<a id=\"ban_link\" href=\"%s\" class=\"button ban-link\" title=\"%s\">%s'\n                    '<i aria-hidden=\"true\" class=\"icon-ban\"></i></a>'\n                    % (url, title, ugettext('Banned')))\n            link_cleanup = ('<a id=\"cleanup_link\" href=\"%s\" class=\"button negative ban-link\">%s'\n                            '<i aria-hidden=\"true\" class=\"icon-ban\"></i></a>'\n                            % (url_ban_cleanup, ugettext('Clean Up Revisions')))\n        else:\n            url = reverse('users.ban_user', kwargs={'username': ban_user.username})\n            link = ('<a id=\"ban_link\" href=\"%s\" class=\"button negative ban-link\">%s'\n                    '<i aria-hidden=\"true\" class=\"icon-ban\"></i></a>'\n                    % (url, ugettext('Ban User')))\n            link_cleanup = ('<a id=\"cleanup_link\" href=\"%s\" class=\"button negative ban-link\">%s'\n                            '<i aria-hidden=\"true\" class=\"icon-ban\"></i></a>'\n                            % (url_ban_cleanup, ugettext('Ban User & Clean Up')))\n        links = link_cleanup + ' ' + link\n    return Markup(links)\n\n\n@library.global_function\ndef admin_link(user):\n    \"\"\"Returns a link to admin a user\"\"\"\n    url = reverse('admin:users_user_change', args=(user.id,),\n                  current_app=admin.site.name)\n    link = ('<a href=\"%s\" class=\"button neutral\">%s'\n            '<i aria-hidden=\"true\" class=\"icon-wrench\"></i></a>' %\n            (url, ugettext('Admin')))\n    return Markup(link)\n\n\n@library.filter\ndef public_email(email):\n    \"\"\"Email address -> publicly displayable email.\"\"\"\n    return Markup('<span class=\"email\">%s</span>' % unicode_to_html(email))\n\n\ndef unicode_to_html(text):\n    \"\"\"Turns all unicode into html entities, e.g. &#69; -> E.\"\"\"\n    return ''.join(['&#%s;' % ord(i) for i in text])\n\n\n@library.global_function\ndef user_list(users):\n    \"\"\"Turn a list of users into a list of links to their profiles.\"\"\"\n    link = '<a href=\"%s\">%s</a>'\n    list = ', '.join([link % (escape(u.get_absolute_url()), escape(u.username))\n                      for u in users])\n    return Markup(list)\n\n\n# Returns a string representation of a user\nlibrary.global_function(user_display)\n\n# Returns a list of social authentication providers.\nlibrary.global_function(get_providers)\n\n\n@library.global_function\n@contextfunction\ndef provider_login_url(context, provider_id, **params):\n    \"\"\"\n    {{ provider_login_url(\"github\", next=\"/some/url\") }}\n    \"\"\"\n    request = context['request']\n    provider = providers.registry.by_id(provider_id)\n    auth_params = params.get('auth_params', None)\n    scope = params.get('scope', None)\n    process = params.get('process', None)\n    if scope == '':\n        del params['scope']\n    if auth_params == '':\n        del params['auth_params']\n    if 'next' not in params:\n        next = get_request_param(request, 'next')\n        if next:\n            params['next'] = next\n        elif process == 'redirect':\n            params['next'] = request.get_full_path()\n    else:\n        if not params['next']:\n            del params['next']\n    # get the login url and append params as url parameters\n    return Markup(provider.get_login_url(request, **params))\n\n\n@library.global_function\n@contextfunction\ndef providers_media_js(context):\n    \"\"\"\n    {{ providers_media_js() }}\n    \"\"\"\n    request = context['request']\n    return Markup('\\n'.join([p.media_js(request)\n                             for p in providers.registry.get_list()]))\n\n\n@library.global_function\ndef social_accounts(user):\n    \"\"\"\n    {% set accounts = social_accounts(user) %}\n\n    Then:\n        {{ accounts.twitter }} -- a list of connected Twitter accounts\n        {{ accounts.twitter.0 }} -- the first Twitter account\n        {% if accounts %} -- if there is at least one social account\n    \"\"\"\n    accounts = {}\n    if not user.is_authenticated:\n        return accounts\n    for account in user.socialaccount_set.all().iterator():\n        providers = accounts.setdefault(account.provider, [])\n        providers.append(account)\n    return accounts\n\n\n@library.global_function\n@library.render_with('honeypot/honeypot_field.html')\ndef honeypot_field(field_name=None):\n    return render_honeypot_field(field_name)\n\n\n@library.global_function\ndef get_primary_email(email_addresses):\n    for email in email_addresses:\n        if email_addresses[email].get('primary'):\n            return email\n\n\n@library.global_function\ndef is_username_taken(username):\n    \"\"\"\n    Returns True if a user with the given username exists (case-insentive),\n    otherwise False.\n    \"\"\"\n    return User.objects.filter(username=username).exists()\n", "path": "kuma/users/templatetags/jinja_helpers.py"}], "after_files": [{"content": "from allauth.account.utils import user_display\nfrom allauth.socialaccount import providers\nfrom allauth.socialaccount.templatetags.socialaccount import get_providers\nfrom allauth.utils import get_request_param\nfrom django.conf import settings\nfrom django.contrib import admin\nfrom django.utils.translation import ugettext\nfrom django_jinja import library\nfrom honeypot.templatetags.honeypot import render_honeypot_field\nfrom jinja2 import contextfunction, escape, Markup\n\nfrom kuma.core.templatetags.jinja_helpers import datetimeformat\nfrom kuma.core.urlresolvers import reverse\n\nfrom ..models import User\n\n\n@library.global_function\ndef get_avatar_url(user):\n    \"\"\"\n    Get the avatar URL of the user's first-joined social account that has one,\n    excluding all Persona social accounts. Assumes that the user is not None or\n    anonymous. If the user has no social account with an avatar, returns the\n    default avatar URL.\n    \"\"\"\n    for account in (user.socialaccount_set\n                        .exclude(provider='persona')\n                        .order_by('date_joined')):\n        avatar_url = account.get_avatar_url()\n        if avatar_url:\n            return avatar_url\n    return settings.DEFAULT_AVATAR\n\n\n@library.global_function\n@contextfunction\ndef ban_links(context, ban_user, banner_user):\n    \"\"\"Returns a link to ban a user\"\"\"\n    links = ''\n    if ban_user.id != banner_user.id and banner_user.has_perm('users.add_userban'):\n        active_ban = ban_user.active_ban\n        url_ban_cleanup = reverse('users.ban_user_and_cleanup',\n                                  kwargs={'username': ban_user.username})\n        if active_ban:\n            url = reverse('admin:users_userban_change', args=(active_ban.id,))\n            title = ugettext('Banned on %(ban_date)s by %(ban_admin)s.') % {\n                'ban_date': datetimeformat(context, active_ban.date,\n                                           format='date', output='json'),\n                'ban_admin': active_ban.by,\n            }\n            link = ('<a id=\"ban_link\" href=\"%s\" class=\"button ban-link\" title=\"%s\">%s'\n                    '<i aria-hidden=\"true\" class=\"icon-ban\"></i></a>'\n                    % (url, title, ugettext('Banned')))\n            link_cleanup = ('<a id=\"cleanup_link\" href=\"%s\" class=\"button negative ban-link\">%s'\n                            '<i aria-hidden=\"true\" class=\"icon-ban\"></i></a>'\n                            % (url_ban_cleanup, ugettext('Clean Up Revisions')))\n        else:\n            url = reverse('users.ban_user', kwargs={'username': ban_user.username})\n            link = ('<a id=\"ban_link\" href=\"%s\" class=\"button negative ban-link\">%s'\n                    '<i aria-hidden=\"true\" class=\"icon-ban\"></i></a>'\n                    % (url, ugettext('Ban User')))\n            link_cleanup = ('<a id=\"cleanup_link\" href=\"%s\" class=\"button negative ban-link\">%s'\n                            '<i aria-hidden=\"true\" class=\"icon-ban\"></i></a>'\n                            % (url_ban_cleanup, ugettext('Ban User & Clean Up')))\n        links = link_cleanup + ' ' + link\n    return Markup(links)\n\n\n@library.global_function\ndef admin_link(user):\n    \"\"\"Returns a link to admin a user\"\"\"\n    url = reverse('admin:users_user_change', args=(user.id,),\n                  current_app=admin.site.name)\n    link = ('<a href=\"%s\" class=\"button neutral\">%s'\n            '<i aria-hidden=\"true\" class=\"icon-wrench\"></i></a>' %\n            (url, ugettext('Admin')))\n    return Markup(link)\n\n\n@library.filter\ndef public_email(email):\n    \"\"\"Email address -> publicly displayable email.\"\"\"\n    return Markup('<span class=\"email\">%s</span>' % unicode_to_html(email))\n\n\ndef unicode_to_html(text):\n    \"\"\"Turns all unicode into html entities, e.g. &#69; -> E.\"\"\"\n    return ''.join(['&#%s;' % ord(i) for i in text])\n\n\n@library.global_function\ndef user_list(users):\n    \"\"\"Turn a list of users into a list of links to their profiles.\"\"\"\n    link = '<a href=\"%s\">%s</a>'\n    list = ', '.join([link % (escape(u.get_absolute_url()), escape(u.username))\n                      for u in users])\n    return Markup(list)\n\n\n# Returns a string representation of a user\nlibrary.global_function(user_display)\n\n# Returns a list of social authentication providers.\nlibrary.global_function(get_providers)\n\n\n@library.global_function\n@contextfunction\ndef provider_login_url(context, provider_id, **params):\n    \"\"\"\n    {{ provider_login_url(\"github\", next=\"/some/url\") }}\n    \"\"\"\n    request = context['request']\n    provider = providers.registry.by_id(provider_id)\n    auth_params = params.get('auth_params', None)\n    scope = params.get('scope', None)\n    process = params.get('process', None)\n    if scope == '':\n        del params['scope']\n    if auth_params == '':\n        del params['auth_params']\n    if 'next' not in params:\n        next = get_request_param(request, 'next')\n        if next:\n            params['next'] = next\n        elif process == 'redirect':\n            params['next'] = request.get_full_path()\n    else:\n        if not params['next']:\n            del params['next']\n    # get the login url and append params as url parameters\n    return Markup(provider.get_login_url(request, **params))\n\n\n@library.global_function\n@contextfunction\ndef providers_media_js(context):\n    \"\"\"\n    {{ providers_media_js() }}\n    \"\"\"\n    request = context['request']\n    return Markup('\\n'.join([p.media_js(request)\n                             for p in providers.registry.get_list()]))\n\n\n@library.global_function\ndef social_accounts(user):\n    \"\"\"\n    {% set accounts = social_accounts(user) %}\n\n    Then:\n        {{ accounts.twitter }} -- a list of connected Twitter accounts\n        {{ accounts.twitter.0 }} -- the first Twitter account\n        {% if accounts %} -- if there is at least one social account\n    \"\"\"\n    accounts = {}\n    if not user.is_authenticated:\n        return accounts\n    for account in user.socialaccount_set.all().iterator():\n        providers = accounts.setdefault(account.provider, [])\n        providers.append(account)\n    return accounts\n\n\n@library.global_function\n@library.render_with('honeypot/honeypot_field.html')\ndef honeypot_field(field_name=None):\n    return render_honeypot_field(field_name)\n\n\n@library.global_function\ndef get_primary_email(email_addresses):\n    for email in email_addresses:\n        if email_addresses[email].get('primary'):\n            return email\n\n\n@library.global_function\ndef is_username_taken(username):\n    \"\"\"\n    Returns True if a user with the given username exists (case-insentive),\n    otherwise False.\n    \"\"\"\n    return User.objects.filter(username=username).exists()\n", "path": "kuma/users/templatetags/jinja_helpers.py"}]}