From e80b97b2b99a6d8927725d10a04aa19589591eed Mon Sep 17 00:00:00 2001 From: Andrew Redden Date: Wed, 3 Jun 2020 16:23:38 -0300 Subject: [PATCH 1/2] fix the 500 error during email change, allowing users to freely change their emails --- app/marketing/utils.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/marketing/utils.py b/app/marketing/utils.py index d417005bec0..6559e8f1ffb 100644 --- a/app/marketing/utils.py +++ b/app/marketing/utils.py @@ -223,12 +223,7 @@ 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 + created, es = EmailSubscriber.objects.get_or_create(email__iexact=email, default=defaults) #print("EmailSubscriber:", es, "- created" if created else "- updated") except EmailSubscriber.MultipleObjectsReturned: email_subscriber_ids = EmailSubscriber.objects.filter(email__iexact=email) \ @@ -247,8 +242,6 @@ def get_or_save_email_subscriber(email, source, send_slack_invite=True, profile= if created or not es.priv: es.set_priv() es.save() - if send_slack_invite: - invite_to_slack(email) return es From fb1cee0b449e5bb997355f0df9aa6f3ffdda4598 Mon Sep 17 00:00:00 2001 From: Andrew Redden Date: Wed, 3 Jun 2020 17:26:45 -0300 Subject: [PATCH 2/2] the fix should use update_or_create not get_or_create --- app/marketing/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/marketing/utils.py b/app/marketing/utils.py index 6559e8f1ffb..30fabdbe155 100644 --- a/app/marketing/utils.py +++ b/app/marketing/utils.py @@ -223,8 +223,8 @@ def get_or_save_email_subscriber(email, source, send_slack_invite=True, profile= created = False try: - created, es = EmailSubscriber.objects.get_or_create(email__iexact=email, default=defaults) - #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) \ @@ -236,7 +236,7 @@ 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: