From 4bcdea6e53817175041461863c9c8f9fc161ef80 Mon Sep 17 00:00:00 2001 From: Brian Beggs Date: Mon, 27 Nov 2023 11:01:08 -0500 Subject: [PATCH] chore: When trimming email addresses ignore failures when removing an email address multiple times. --- license_manager/apps/api/v1/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/license_manager/apps/api/v1/views.py b/license_manager/apps/api/v1/views.py index 8c90f93d..9eadcf21 100644 --- a/license_manager/apps/api/v1/views.py +++ b/license_manager/apps/api/v1/views.py @@ -1,5 +1,6 @@ import logging from collections import OrderedDict +from contextlib import suppress from uuid import uuid4 from celery import chain @@ -654,7 +655,9 @@ def _trim_already_associated_emails(self, subscription_plan, user_emails): already_associated_licenses.values_list('user_email', flat=True) ) for email in already_associated_emails: - trimmed_emails.remove(email.lower()) + # Ignore error if email was already removed from the list e.g. email has multiple licenses assigned + with suppress(ValueError): + trimmed_emails.remove(email.lower()) return trimmed_emails, already_associated_emails