Skip to content

Commit

Permalink
[BUG]: Change email fix (#6761)
Browse files Browse the repository at this point in the history
* fix the 500 error during email change, allowing users to freely change their emails

* the fix should use update_or_create not get_or_create

Co-authored-by: Dan Lipert <[email protected]>
  • Loading branch information
androolloyd and danlipert authored Jul 9, 2020
1 parent 77fd4ef commit 1aa584d
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions app/marketing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,8 @@ def get_or_save_email_subscriber(email, source, send_slack_invite=True, profile=

created = False
try:
already_exists = EmailSubscriber.objects.filter(email__iexact=email)
if already_exists.exists():
es = already_exists.first()
else:
es = EmailSubscriber.objects.create(**defaults)
created = True
#print("EmailSubscriber:", es, "- created" if created else "- updated")
es, created = EmailSubscriber.objects.update_or_create(email__iexact=email, defaults=defaults)
# print("EmailSubscriber:", es, "- created" if created else "- updated")
except EmailSubscriber.MultipleObjectsReturned:
email_subscriber_ids = EmailSubscriber.objects.filter(email__iexact=email) \
.values_list('id', flat=True) \
Expand All @@ -241,14 +236,12 @@ def get_or_save_email_subscriber(email, source, send_slack_invite=True, profile=
es = EmailSubscriber.objects.create(**defaults)
created = True
except Exception as e:
#print(f'Failed to update or create email subscriber: ({email}) - {e}')
# print(f'Failed to update or create email subscriber: ({email}) - {e}')
return ''

if created or not es.priv:
es.set_priv()
es.save()
if send_slack_invite:
invite_to_slack(email)

return es

Expand Down

0 comments on commit 1aa584d

Please sign in to comment.