Skip to content

Fix problem with context data on password reset email #2453

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions readthedocs/core/adapters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Allauth overrides"""

import pickle
import logging

from allauth.account.adapter import DefaultAccountAdapter
from django.template.loader import render_to_string

Expand All @@ -10,6 +13,8 @@
except ImportError:
from django.utils.encoding import force_unicode as force_text

log = logging.getLogger(__name__)


class AccountAdapter(DefaultAccountAdapter):

Expand All @@ -25,6 +30,19 @@ def send_mail(self, template_prefix, email, context):
subject = " ".join(subject.splitlines()).strip()
subject = self.format_email_subject(subject)

# Allauth sends some additional data in the context, remove it if the
# pieces can't be pickled
removed_keys = []
for key in context.keys():
try:
_ = pickle.dumps(context[key])
except pickle.PickleError:
removed_keys.append(key)
del context[key]
if removed_keys:
log.debug('Removed context we were unable to serialize: %s',
removed_keys)

send_email(
recipient=email,
subject=subject,
Expand Down